From 15c0931dcdec5350afd5d561787212b3481e17fa Mon Sep 17 00:00:00 2001 From: Anthex Date: Fri, 26 Apr 2019 21:30:07 +0200 Subject: [PATCH] add script to export 3D visualisation of N-Lateration result --- .gitignore | 1 + README.md | 24 +++++++++++------------- structure.py | 15 +++++++++------ visuals.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 visuals.py diff --git a/.gitignore b/.gitignore index fef6a83..021e161 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __pycache__/ .pytest_cache/ coverage.xml .coverage +out.gif diff --git a/README.md b/README.md index b6574b0..d65f43e 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,22 @@ -[![Build Status](https://travis-ci.com/Anthex/LO53FP.svg?branch=master)](https://travis-ci.com/Anthex/LO53FP) [![codecov](https://codecov.io/gh/Anthex/LO53FP/branch/master/graph/badge.svg)](https://codecov.io/gh/Anthex/LO53FP) [![CodeFactor](https://www.codefactor.io/repository/github/anthex/lo53fp/badge)](https://www.codefactor.io/repository/github/anthex/lo53fp) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) - -[UTBM - LO53] - Python fingerprinting - -Achille Dantz +[![Build Status](https://travis-ci.com/Anthex/LO53FP.svg?branch=master)](https://travis-ci.com/Anthex/LO53FP) [![codecov](https://codecov.io/gh/Anthex/LO53FP/branch/master/graph/badge.svg)](https://codecov.io/gh/Anthex/LO53FP) [![CodeFactor](https://www.codefactor.io/repository/github/anthex/lo53fp/badge)](https://www.codefactor.io/repository/github/anthex/lo53fp) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) - +# [UTBM - LO53] - Python fingerprinting +Documentation : https://dantz.fr/LO53/structure.html +**Author** : Achille Dantz +## Description This program aims to compute the approximate location of a mobile terminal for a known set of Wi-Fi accesspoints in an ideal 12x12m space for which we have 9 fingerprinting values (known RSSI for each accesspoint at a given location) - +### Main.py Example Output : -Documentation : https://dantz.fr/LO53/structure.html - - +![Screencap](https://dantz.fr/LO53/Capture_.PNG) -Example Output : +## Annex : N-Lateration 3D visualisation +visuals.py provides a cool function to graphically represent the N-Lateration distances in a 3D space by creating an animated gif (RMI style) +### Example : + ![enter image description here](https://dantz.fr/LO53/out.gif) - -![Screencap](https://dantz.fr/LO53/Capture_.PNG) \ No newline at end of file diff --git a/structure.py b/structure.py index e4ba74b..3f06356 100644 --- a/structure.py +++ b/structure.py @@ -1,5 +1,5 @@ from operator import itemgetter as ig -from math import floor, sqrt +from math import floor, sqrt, ceil, log, exp from numpy import arange class RSSVector(): distances = [] @@ -277,22 +277,25 @@ def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0): :param xSize: The X dimension of the cuboid containing all the emitters (automatically computed if not specified) :param ySize: The Y dimension of the cuboid containing all the emitters (automatically computed if not specified) :param zSize: The Z dimension of the cuboid containing all the emitters (automatically computed if not specified) + :return: args 4 and 5 are the x/y dimensions of the cuboid, imageArray contains and image of the distances for graphic representation ''' minLoc = Location() minDist = 0.0 + #gifArray = [] for k in data: minDist += abs(k[0].distanceTo(Location()) - k[1]) xSize = k[0].x if k[0].x > xSize else xSize ySize = k[0].y if k[0].y > ySize else ySize zSize = k[0].z if k[0].z > zSize else zSize - for k in arange(0.1,xSize,step): - for l in arange(0.1,ySize,step): - for m in arange(0.1,zSize,step): + imageArray=[[] for i in range(0,floor(zSize*10))] + for k in arange(0,xSize,step): + for l in arange(0,ySize,step): + for m in arange(0,zSize,step): d = .0 for n in data: d += abs(n[0].distanceTo(Location(k,l,m)) - n[1]) if d < minDist: minDist = d minLoc = Location(round(k,2),round(l,2),round(m,2)) - return (minLoc, minDist) - \ No newline at end of file + imageArray[floor(l*10)].append(d*10+255-min(10+exp(d*2),255)) + return (minLoc, minDist, imageArray[0], floor(ySize/step), floor(xSize/step), imageArray) diff --git a/visuals.py b/visuals.py new file mode 100644 index 0000000..870a986 --- /dev/null +++ b/visuals.py @@ -0,0 +1,30 @@ +from structure import RSSVector, Location, Cell, newCell, KNeighbors, resolve_barycenter, MarkovModel, NLateration +from random import random +from math import floor, sqrt, ceil +from PIL import Image, ImageDraw +from os import startfile + +#dataset : list of tuples representing emitters (Location, distance) +dataset = [(Location(.5,.5,.5), 3.0), (Location(4.0,.0,.0), 2.0), (Location(4.0,5.0,5.0), 4.2), (Location(3.0,3.0,3.0), 2.5)] + +NLat_result = NLateration(dataset) + +W,H = NLat_result[3], NLat_result[4] + +frames = [] + +def createFrame(x,y,nbr): + img = Image.new("L",(x,y)) + img.putdata(NLat_result[5][nbr]) + return img + +for i in range(len(NLat_result[5])): + newFrame = createFrame(W,H,i) + newFrame = newFrame.resize((W*10,H*10), Image.ANTIALIAS) + draw = ImageDraw.Draw(newFrame) + draw.text(text="z="+str(i), xy=(0,0)) + frames.append(newFrame) + +frames[0].save("out.gif", format="GIF", append_images=frames[1:], save_all=True, duration=100, loop=0) +print("gif exported") + -- libgit2 0.21.4