-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirvis.py
47 lines (32 loc) · 937 Bytes
/
irvis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import can
import cv2
import numpy
data = numpy.zeros((8, 8), dtype=numpy.float32)
def process_can(bus):
msg = bus.recv(0)
if msg is None:
return False
if not (0x100 <= msg.arbitration_id <= 0x107):
return True
num_sensor = msg.arbitration_id - 0x100
for i in range(8):
data[7 - num_sensor][i] = msg.data[i]
return True
def main():
bus = can.interface.Bus('can0', bustype='socketcan_native')
while True:
while process_can(bus):
pass
data[7][0] = numpy.average(data)
img = data.copy()
img -= img.min()
img *= 255/(img.max()+1)
img = cv2.resize(img, (512, 512))
img = cv2.applyColorMap(img.astype(numpy.uint8), cv2.COLORMAP_JET)
cv2.imshow('IR data', img)
key = cv2.waitKey(10)
if key == 27:
break
cv2.destroyAllWindows()
if __name__ == "__main__":
main()