SHARE
TWEET

Untitled

a guest Feb 18th, 2020 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2. import math
  3. import cv2
  4. import numpy as np
  5.  
  6. def loadFromFile(file):
  7.     distances = {v:0 for v in range(0, 360)}
  8.     max = 0
  9.     pattern = re.compile(r'(?<=\[)(.*?)(?=\])')
  10.     with open(file) as f:
  11.         data = f.read()
  12.         for datapoint in re.split(',', data):
  13.             s = pattern.search(datapoint)
  14.             print(s)
  15.             dist = float(datapoint.split('=')[-1])
  16.             distances[int(s.group(0))] = dist
  17.  
  18.     return distances
  19.  
  20. def computeCoords(angleCoords, datapoint, scale, center, degrees):
  21.     print(degrees)
  22.     coord = (math.floor(scale * datapoint * math.cos(math.radians(degrees))), math.floor(scale * datapoint * math.sin(math.radians(degrees))))
  23.     angleCoords[degrees] = (coord[0] + center[0], coord[1] + center[1])
  24.  
  25. def graph(angleCoords, img, size):
  26.     for i in angleCoords:
  27.         if angleCoords[i][0] != 0: print(angleCoords[i])
  28.         img[angleCoords[i][1]][angleCoords[i][0]] = 255
  29.  
  30. def normalize(max, d):
  31.     return {x:d[x]/max for x in d}
  32.  
  33. def main():
  34.     size = (501, 501)
  35.     scale = 20
  36.     img = np.zeros(size)
  37.     cv2.imshow("lidar", img)
  38.     cv2.waitKey(1)
  39.     max = 0
  40.     data = {v:0 for v in range(0, 360)}
  41.     normalized = {v:() for v in range(0, 360)}
  42.     realdata = loadFromFile('values.txt')
  43.     angleCoords = {v:(0, 0) for v in range(0, 360)}
  44.     center = (math.floor(size[0]/2), math.floor(size[1]/2))
  45.     for x in realdata:
  46.         data[x] = realdata[x]
  47.         if realdata[x] > max:
  48.             normalized = normalize(realdata[x], data)
  49.             max = realdata[x]
  50.  
  51.         img = np.zeros(size)
  52.  
  53.         computeCoords(angleCoords, realdata[x], scale, center, x)
  54.         graph(angleCoords, img, size)
  55.         cv2.imshow("lidar", img)
  56.         cv2.waitKey(1)
  57.  
  58. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top