1
1
import argparse
2
2
3
3
import cv2 as cv
4
+ import numpy as np
4
5
import glog as log
6
+
5
7
from openvino .inference_engine import IECore
8
+ from icecream import ic
6
9
7
10
from torchdet3d .utils import draw_kp , Regressor , Detector , OBJECTRON_CLASSES , MultiCameraTracker
8
11
9
12
10
13
def draw_detections (frame , reg_detections , det_detections , reg_only = True ):
11
14
"""Draws detections and labels"""
12
15
for det_out , reg_out in zip (det_detections , reg_detections ):
13
- left , top , right , bottom = det_out [0 ]
16
+ left , top , right , bottom = det_out [: 4 ]
14
17
kp = reg_out [0 ]
15
18
label = reg_out [1 ]
16
19
label = OBJECTRON_CLASSES [label ]
@@ -34,8 +37,7 @@ def run(params, capture, detector, regressor, write_video=False, resolution = (1
34
37
vout = cv .VideoWriter ()
35
38
vout .open ('output_video_demo.mp4' ,fourcc ,fps ,resolution ,True )
36
39
win_name = '3D-object-detection'
37
- tracker = MultiCameraTracker (1 , None , visual_analyze = None )
38
-
40
+ tracker = MultiCameraTracker (1 , None )
39
41
40
42
has_frame , prev_frame = capture .read ()
41
43
prev_frame = cv .resize (prev_frame , resolution )
@@ -49,13 +51,17 @@ def run(params, capture, detector, regressor, write_video=False, resolution = (1
49
51
frame = cv .resize (frame , resolution )
50
52
detections = detector .wait_and_grab ()
51
53
detector .run_async (frame )
52
-
53
- tracker .process (prev_frame , detections , None )
54
+ ic ( detections )
55
+ tracker .process (np . expand_dims ( prev_frame , 0 ), [ detections ] , None )
54
56
tracked_objects = tracker .get_tracked_objects ()
55
-
56
- outputs = regressor .get_detections (prev_frame , tracked_objects )
57
-
58
- vis = draw_detections (prev_frame , outputs , detections , reg_only = False )
57
+ ic (tracked_objects )
58
+ if all (tracked_objects ):
59
+ rectangles = [rect .rect for rect in tracked_objects [0 ]]
60
+ else :
61
+ rectangles = detections
62
+ outputs = regressor .get_detections (prev_frame , rectangles )
63
+
64
+ vis = draw_detections (prev_frame , outputs , rectangles , reg_only = False )
59
65
cv .imshow (win_name , vis )
60
66
if write_video :
61
67
vout .write (vis )
0 commit comments