-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapture_loop.py
37 lines (26 loc) · 1.1 KB
/
capture_loop.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
import logging
import time
from object_detector import ObjectDetector
LOG = logging.getLogger(__name__)
def run_capture_loop(capture, object_detector: ObjectDetector, result_queue):
LOG.info('running capture loop...')
while True:
then = time.time()
ret, frame = capture.read()
timestamp = time.time() # frame timestamp
_, labels, positions, heights, widths = object_detector.estimate_pose(frame, viz=False)
if LOG.isEnabledFor(logging.DEBUG):
LOG.info('object_detection took %.4f s', time.time() - then)
for i in range(len(labels)):
position = positions[i]
label = labels[i]
height = float(heights[i])
width = float(widths[i])
message = {
'Timestamp': timestamp,
'Type': label,
'Position': {'X': float(position[0]), 'Y': float(position[1]), 'Z': float(position[2])},
'Shape': [{'X': width, 'Y': 0.0, 'Z': height}]
}
LOG.debug('queueing message %s', message)
result_queue.put(message)