Commit 15c0931dcdec5350afd5d561787212b3481e17fa
1 parent
d67a28b9
add script to export 3D visualisation of N-Lateration result
Showing
4 changed files
with
51 additions
and
19 deletions
Show diff stats
.gitignore
README.md
1 | 1 | ||
2 | -[](https://travis-ci.com/Anthex/LO53FP) [](https://codecov.io/gh/Anthex/LO53FP) [](https://www.codefactor.io/repository/github/anthex/lo53fp) [](https://opensource.org/licenses/MIT) | ||
3 | - | ||
4 | 2 | ||
5 | 3 | ||
6 | -[UTBM - LO53] - Python fingerprinting | ||
7 | - | ||
8 | -Achille Dantz <achille@dantz.fr> | 4 | +[](https://travis-ci.com/Anthex/LO53FP) [](https://codecov.io/gh/Anthex/LO53FP) [](https://www.codefactor.io/repository/github/anthex/lo53fp) [](https://opensource.org/licenses/MIT) |
9 | 5 | ||
10 | - | 6 | +# [UTBM - LO53] - Python fingerprinting |
7 | +Documentation : https://dantz.fr/LO53/structure.html | ||
8 | +**Author** : Achille Dantz <achille@dantz.fr> | ||
11 | 9 | ||
10 | +## Description | ||
12 | 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) | 11 | 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) |
13 | 12 | ||
14 | - | 13 | +### Main.py Example Output : |
15 | 14 | ||
16 | -Documentation : https://dantz.fr/LO53/structure.html | ||
17 | - | ||
18 | - | 15 | + |
19 | 16 | ||
20 | -Example Output : | 17 | +## Annex : N-Lateration 3D visualisation |
18 | +visuals.py provides a cool function to graphically represent the N-Lateration distances in a 3D space by creating an animated gif (RMI style) | ||
19 | +### Example : | ||
20 | +  | ||
21 | 21 | ||
22 | 22 | ||
23 | - | ||
24 | - | ||
25 | \ No newline at end of file | 23 | \ No newline at end of file |
structure.py
1 | from operator import itemgetter as ig | 1 | from operator import itemgetter as ig |
2 | -from math import floor, sqrt | 2 | +from math import floor, sqrt, ceil, log, exp |
3 | from numpy import arange | 3 | from numpy import arange |
4 | class RSSVector(): | 4 | class RSSVector(): |
5 | distances = [] | 5 | distances = [] |
@@ -277,22 +277,25 @@ def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0): | @@ -277,22 +277,25 @@ def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0): | ||
277 | :param xSize: The X dimension of the cuboid containing all the emitters (automatically computed if not specified) | 277 | :param xSize: The X dimension of the cuboid containing all the emitters (automatically computed if not specified) |
278 | :param ySize: The Y dimension of the cuboid containing all the emitters (automatically computed if not specified) | 278 | :param ySize: The Y dimension of the cuboid containing all the emitters (automatically computed if not specified) |
279 | :param zSize: The Z dimension of the cuboid containing all the emitters (automatically computed if not specified) | 279 | :param zSize: The Z dimension of the cuboid containing all the emitters (automatically computed if not specified) |
280 | + :return: args 4 and 5 are the x/y dimensions of the cuboid, imageArray contains and image of the distances for graphic representation | ||
280 | ''' | 281 | ''' |
281 | minLoc = Location() | 282 | minLoc = Location() |
282 | minDist = 0.0 | 283 | minDist = 0.0 |
284 | + #gifArray = [] | ||
283 | for k in data: | 285 | for k in data: |
284 | minDist += abs(k[0].distanceTo(Location()) - k[1]) | 286 | minDist += abs(k[0].distanceTo(Location()) - k[1]) |
285 | xSize = k[0].x if k[0].x > xSize else xSize | 287 | xSize = k[0].x if k[0].x > xSize else xSize |
286 | ySize = k[0].y if k[0].y > ySize else ySize | 288 | ySize = k[0].y if k[0].y > ySize else ySize |
287 | zSize = k[0].z if k[0].z > zSize else zSize | 289 | zSize = k[0].z if k[0].z > zSize else zSize |
288 | - for k in arange(0.1,xSize,step): | ||
289 | - for l in arange(0.1,ySize,step): | ||
290 | - for m in arange(0.1,zSize,step): | 290 | + imageArray=[[] for i in range(0,floor(zSize*10))] |
291 | + for k in arange(0,xSize,step): | ||
292 | + for l in arange(0,ySize,step): | ||
293 | + for m in arange(0,zSize,step): | ||
291 | d = .0 | 294 | d = .0 |
292 | for n in data: | 295 | for n in data: |
293 | d += abs(n[0].distanceTo(Location(k,l,m)) - n[1]) | 296 | d += abs(n[0].distanceTo(Location(k,l,m)) - n[1]) |
294 | if d < minDist: | 297 | if d < minDist: |
295 | minDist = d | 298 | minDist = d |
296 | minLoc = Location(round(k,2),round(l,2),round(m,2)) | 299 | minLoc = Location(round(k,2),round(l,2),round(m,2)) |
297 | - return (minLoc, minDist) | ||
298 | - | ||
299 | \ No newline at end of file | 300 | \ No newline at end of file |
301 | + imageArray[floor(l*10)].append(d*10+255-min(10+exp(d*2),255)) | ||
302 | + return (minLoc, minDist, imageArray[0], floor(ySize/step), floor(xSize/step), imageArray) |
1 | +from structure import RSSVector, Location, Cell, newCell, KNeighbors, resolve_barycenter, MarkovModel, NLateration | ||
2 | +from random import random | ||
3 | +from math import floor, sqrt, ceil | ||
4 | +from PIL import Image, ImageDraw | ||
5 | +from os import startfile | ||
6 | + | ||
7 | +#dataset : list of tuples representing emitters (Location, distance) | ||
8 | +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)] | ||
9 | + | ||
10 | +NLat_result = NLateration(dataset) | ||
11 | + | ||
12 | +W,H = NLat_result[3], NLat_result[4] | ||
13 | + | ||
14 | +frames = [] | ||
15 | + | ||
16 | +def createFrame(x,y,nbr): | ||
17 | + img = Image.new("L",(x,y)) | ||
18 | + img.putdata(NLat_result[5][nbr]) | ||
19 | + return img | ||
20 | + | ||
21 | +for i in range(len(NLat_result[5])): | ||
22 | + newFrame = createFrame(W,H,i) | ||
23 | + newFrame = newFrame.resize((W*10,H*10), Image.ANTIALIAS) | ||
24 | + draw = ImageDraw.Draw(newFrame) | ||
25 | + draw.text(text="z="+str(i), xy=(0,0)) | ||
26 | + frames.append(newFrame) | ||
27 | + | ||
28 | +frames[0].save("out.gif", format="GIF", append_images=frames[1:], save_all=True, duration=100, loop=0) | ||
29 | +print("gif exported") | ||
30 | + |