555
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.1 KiB

  1. import readGridEyeData
  2. import sys
  3. import numpy as np
  4. import cv2
  5. SIZE = 8
  6. visible_size = 128
  7. distanceBetweenSensors_w = 2.6 #cm
  8. distanceBetweenSensors_h = 2.6 #cm
  9. distance2Object = 60.0 #cm
  10. OFFSET = ((0, 0), ())
  11. TEMP_SCALE = 20
  12. RED = (0, 0, 255)
  13. GREEN = (0, 255, 0)
  14. BLUE = (255, 0, 0)
  15. background = readGridEyeData.GridEyeData(sys.argv[1])
  16. background_frames = [np.zeros((SIZE,SIZE)), np.zeros((SIZE,SIZE)),
  17. np.zeros((SIZE,SIZE)), np.zeros((SIZE,SIZE))]
  18. cnt = 1
  19. Horizon_array = np.array([[x for x in range(8)] for _ in range(8)])
  20. Vertical_array = np.array([[x for _ in range(8)] for x in range(8)])
  21. # Gets background of each pixel.
  22. while background.readFrame():
  23. frames = background.frames
  24. for i in range(4):
  25. background_frames[i] += np.array(frames[i].data)
  26. cnt += 1
  27. for i in range(4):
  28. background_frames[i]/=cnt
  29. # Reads data from object frames.
  30. objects = readGridEyeData.GridEyeData(sys.argv[2])
  31. while objects.readFrame():
  32. frames = objects.frames
  33. imgs = []
  34. heat_points = []
  35. # Subtracts background and scale the value.
  36. for i in range(4):
  37. frame = np.array(frames[i].data) - background_frames[i]
  38. frame[frame < 0] = 0.0
  39. frame *= TEMP_SCALE
  40. frame[frame > 255] = 255
  41. imgs.append(frame.astype(np.uint8))
  42. x = int(sum(sum(frame * Horizon_array)) / sum(sum(frame)) / (SIZE - 1) *
  43. (visible_size - 1))
  44. y = int(sum(sum(frame * Vertical_array)) / sum(sum(frame)) / (SIZE - 1) *
  45. (visible_size - 1))
  46. heat_points.append((x,y))
  47. print (x, y)
  48. all_img = np.concatenate((np.concatenate((imgs[0], imgs[1]), axis = 1),
  49. np.concatenate((imgs[2], imgs[3]), axis = 1)),
  50. axis = 0)
  51. all_img = cv2.cvtColor(all_img, cv2.COLOR_GRAY2RGB)
  52. all_img = cv2.resize(all_img, (visible_size*2, visible_size*2),
  53. interpolation = cv2.INTER_NEAREST)
  54. cv2.circle(all_img, heat_points[0], 5, RED, -1)
  55. cv2.circle(all_img, (heat_points[1][0]+visible_size, heat_points[1][1]), 5, RED, -1)
  56. cv2.imshow('sample', all_img)
  57. while cv2.getWindowProperty('sample', 0) >= 0:
  58. key = cv2.waitKey(50)
  59. if key >= 0:
  60. break