@@ -122,21 +122,23 @@ def video_capture(stop_flag, input_path, raw_frame_queue, preprocessed_frame_que
122
122
cap .release ()
123
123
124
124
125
- def inference (stop_flag , preprocessed_frame_queue , detections_queue , fps_queue ):
125
+ def inference (stop_flag , preprocessed_frame_queue , detections_queue , fps_queue ,
126
+ network , class_names , threshold ):
126
127
while not stop_flag .is_set ():
127
128
darknet_image = preprocessed_frame_queue .get ()
128
129
prev_time = time .time ()
129
- detections = darknet .detect_image (network , class_names , darknet_image , thresh = args .thresh )
130
- detections_queue .put (detections )
130
+ detections = darknet .detect_image (network , class_names , darknet_image , thresh = threshold )
131
131
fps = 1 / (time .time () - prev_time )
132
+ detections_queue .put (detections )
132
133
fps_queue .put (int (fps ))
133
134
print ("FPS: {:.2f}" .format (fps ))
134
135
darknet .print_detections (detections , args .ext_output )
135
136
darknet .free_image (darknet_image )
136
137
137
138
138
- def drawing (stop_flag , input_video_fps , raw_frame_queue , detections_queue , fps_queue , preproc_h , preproc_w , vid_h , vid_w ):
139
+ def drawing (stop_flag , input_video_fps , queues , preproc_h , preproc_w , vid_h , vid_w ):
139
140
random .seed (3 ) # deterministic bbox colors
141
+ raw_frame_queue , preprocessed_frame_queue , detections_queue , fps_queue = queues
140
142
video = set_saved_video (args .out_filename , (vid_w , vid_h ), input_video_fps )
141
143
fps = 1
142
144
while not stop_flag .is_set ():
@@ -184,9 +186,9 @@ def drawing(stop_flag, input_video_fps, raw_frame_queue, detections_queue, fps_q
184
186
cap .release ()
185
187
del cap
186
188
187
- stop_flag = threading .Event ()
188
189
ExecUnit = threading .Thread
189
190
Queue = queue .Queue
191
+ stop_flag = threading .Event ()
190
192
191
193
raw_frame_queue = Queue ()
192
194
preprocessed_frame_queue = Queue (maxsize = 1 )
@@ -196,8 +198,10 @@ def drawing(stop_flag, input_video_fps, raw_frame_queue, detections_queue, fps_q
196
198
exec_units = (
197
199
ExecUnit (target = video_capture , args = (stop_flag , input_path , raw_frame_queue , preprocessed_frame_queue ,
198
200
darknet_height , darknet_width )),
199
- ExecUnit (target = inference , args = (stop_flag , preprocessed_frame_queue , detections_queue , fps_queue )),
200
- ExecUnit (target = drawing , args = (stop_flag , video_fps , raw_frame_queue , detections_queue , fps_queue ,
201
+ ExecUnit (target = inference , args = (stop_flag , preprocessed_frame_queue , detections_queue , fps_queue ,
202
+ network , class_names , args .thresh )),
203
+ ExecUnit (target = drawing , args = (stop_flag , video_fps ,
204
+ (raw_frame_queue , preprocessed_frame_queue , detections_queue , fps_queue ),
201
205
darknet_height , darknet_width , video_height , video_width )),
202
206
)
203
207
for exec_unit in exec_units :
0 commit comments