-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdvs128_thread_test.py
92 lines (77 loc) · 2.76 KB
/
dvs128_thread_test.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""DVS128 Threaded Test.
Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""
from __future__ import print_function
from queue import Queue
import threading
import numpy as np
import cv2
from pyaer.dvs128 import DVS128
device = DVS128()
print ("Device ID:", device.device_id)
if device.device_is_master:
print ("Device is master.")
else:
print ("Device is slave.")
print ("Device Serial Number:", device.device_serial_number)
print ("Device String:", device.device_string)
print ("Device USB bus Number:", device.device_usb_bus_number)
print ("Device USB device address:", device.device_usb_device_address)
print ("Device size X:", device.dvs_size_X)
print ("Device size Y:", device.dvs_size_Y)
print ("Logic Version:", device.logic_version)
# load new config
device.set_bias_from_json("./scripts/configs/dvs128_config.json")
print (device.get_bias())
device.start_data_stream()
# global variable
clip_value = 3
histrange = [(0, v) for v in (128, 128)]
def drawing_func(in_q):
while threading.currentThread().isAlive():
try:
(pol_events, num_pol_event,
special_events, num_special_event) = in_q.get()
if num_pol_event != 0:
pol_on = (pol_events[:, 3] == 1)
pol_off = np.logical_not(pol_on)
img_on, _, _ = np.histogram2d(
pol_events[pol_on, 2], pol_events[pol_on, 1],
bins=(128, 128), range=histrange)
img_off, _, _ = np.histogram2d(
pol_events[pol_off, 1], pol_events[pol_off, 0],
bins=(128, 128), range=histrange)
if clip_value is not None:
integrated_img = np.clip(
(img_on-img_off), -clip_value, clip_value)
else:
integrated_img = (img_on-img_off)
img = integrated_img+clip_value
cv2.imshow("image", img/float(clip_value*2))
cv2.waitKey(1)
except KeyboardInterrupt:
device.shutdown()
break
def fetching_func(out_q):
while threading.currentThread().isAlive():
try:
event_packet = device.get_event()
print ("Number of events:", event_packet[1],
"Number of special events:",
event_packet[3])
out_q.put(event_packet)
except KeyboardInterrupt:
device.shutdown()
break
if __name__ == "__main__":
# define thread
q = Queue(maxsize=1)
drawer = threading.Thread(
name="drawer", target=drawing_func, args=(q, ))
fetcher = threading.Thread(
name="fetcher", target=fetching_func, args=(q, ))
fetcher.start()
print ("fetcher started")
drawer.start()
print ("drawer started")