33import time
44import argparse
55import numpy as np
6+ import subprocess as sp
7+ import json
68import tensorflow as tf
79
810from queue import Queue
911from threading import Thread
10- from utils .app_utils import FPS , WebcamVideoStream , draw_boxes_and_labels
12+ from utils .app_utils import FPS , HLSVideoStream , WebcamVideoStream , draw_boxes_and_labels
1113from object_detection .utils import label_map_util
1214
1315CWD_PATH = os .getcwd ()
@@ -83,22 +85,29 @@ def worker(input_q, output_q):
8385
8486if __name__ == '__main__' :
8587 parser = argparse .ArgumentParser ()
88+ parser .add_argument ('-strin' , '--stream-input' , dest = "stream_in" , action = 'store' , type = str , default = None )
8689 parser .add_argument ('-src' , '--source' , dest = 'video_source' , type = int ,
8790 default = 0 , help = 'Device index of the camera.' )
8891 parser .add_argument ('-wd' , '--width' , dest = 'width' , type = int ,
89- default = 480 , help = 'Width of the frames in the video stream.' )
92+ default = 640 , help = 'Width of the frames in the video stream.' )
9093 parser .add_argument ('-ht' , '--height' , dest = 'height' , type = int ,
91- default = 360 , help = 'Height of the frames in the video stream.' )
94+ default = 480 , help = 'Height of the frames in the video stream.' )
95+ parser .add_argument ('-strout' ,'--stream-output' , dest = "stream_out" , help = 'The URL to send the livestreamed object detection to.' )
9296 args = parser .parse_args ()
9397
94- input_q = Queue (5 ) # fps is better if queue is higher but then more lags
98+ input_q = Queue (1 ) # fps is better if queue is higher but then more lags
9599 output_q = Queue ()
96100 for i in range (1 ):
97101 t = Thread (target = worker , args = (input_q , output_q ))
98102 t .daemon = True
99103 t .start ()
100104
101- video_capture = WebcamVideoStream (src = args .video_source ,
105+ if (args .stream_in ):
106+ print ('Reading from hls stream.' )
107+ video_capture = HLSVideoStream (src = args .stream_in ).start ()
108+ else :
109+ print ('Reading from webcam.' )
110+ video_capture = WebcamVideoStream (src = args .video_source ,
102111 width = args .width ,
103112 height = args .height ).start ()
104113 fps = FPS ().start ()
@@ -125,7 +134,10 @@ def worker(input_q, output_q):
125134 int (point ['ymin' ] * args .height ) - 10 ), color , - 1 , cv2 .LINE_AA )
126135 cv2 .putText (frame , name [0 ], (int (point ['xmin' ] * args .width ), int (point ['ymin' ] * args .height )), font ,
127136 0.3 , (0 , 0 , 0 ), 1 )
128- cv2 .imshow ('Video' , frame )
137+ if args .stream_out :
138+ print ('Streaming elsewhere!' )
139+ else :
140+ cv2 .imshow ('Video' , frame )
129141
130142 fps .update ()
131143
0 commit comments