@@ -216,35 +216,65 @@ def get_video_dev_by_name(src):
216216 exit ()
217217
218218
219- print ("[INFO] Searching for USB camera ..." )
220- dev_video = get_video_dev_by_name ("uvcvideo" )
221- dev_media = get_media_dev_by_name ("uvcvideo" )
222- print (dev_video )
223- print (dev_media )
224-
225- if dev_video == None :
226- input_video = 0
227- elif args .input != "" :
228- input_video = args .input
229- else :
230- input_video = dev_video
231- print ("[INFO] Input Video : " ,input_video )
219+ bInputImage = False
220+ bInputVideo = False
221+ bInputCamera = True
222+
223+ if os .path .exists (args .input ):
224+ print ("[INFO] Input exists : " ,args .input )
225+ file_name , file_extension = os .path .splitext (args .input )
226+ file_extension = file_extension .lower ()
227+ print ("[INFO] Input type : " ,file_extension )
228+ if file_extension == ".jpg" or file_extension == ".png" or file_extension == ".tif" :
229+ bInputImage = True
230+ bInputVideo = False
231+ bInputCamera = False
232+ if file_extension == ".mov" or file_extension == ".mp4" :
233+ bInputImage = False
234+ bInputVideo = True
235+ bInputCamera = False
236+
237+ if bInputCamera == True :
238+ print ("[INFO] Searching for USB camera ..." )
239+ dev_video = get_video_dev_by_name ("uvcvideo" )
240+ dev_media = get_media_dev_by_name ("uvcvideo" )
241+ print (dev_video )
242+ print (dev_media )
243+
244+ if dev_video == None :
245+ input_video = 0
246+ elif args .input != "" :
247+ input_video = args .input
248+ else :
249+ input_video = dev_video
250+
251+ # Open video
252+ cap = cv2 .VideoCapture (input_video )
253+ frame_width = 640
254+ frame_height = 480
255+ cap .set (cv2 .CAP_PROP_FRAME_WIDTH ,frame_width )
256+ cap .set (cv2 .CAP_PROP_FRAME_HEIGHT ,frame_height )
257+ #frame_width = int(round(cap.get(cv2.CAP_PROP_FRAME_WIDTH)))
258+ #frame_height = int(round(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
259+ print ("[INFO] input : camera" ,input_video ," (" ,frame_width ,"," ,frame_height ,")" )
260+
261+ if bInputVideo == True :
262+ # Open video file
263+ cap = cv2 .VideoCapture (args .input )
264+ frame_width = int (round (cap .get (cv2 .CAP_PROP_FRAME_WIDTH )))
265+ frame_height = int (round (cap .get (cv2 .CAP_PROP_FRAME_HEIGHT )))
266+ print ("[INFO] input : video " ,args .input ," (" ,frame_width ,"," ,frame_height ,")" )
267+
268+ if bInputImage == True :
269+ image = cv2 .imread (args .input )
270+ frame_height ,frame_width ,_ = image .shape
271+ print ("[INFO] input : image " ,args .input ," (" ,frame_width ,"," ,frame_height ,")" )
232272
233273output_dir = './captured-images'
234274
235275if not os .path .exists (output_dir ):
236276 os .mkdir (output_dir ) # Create the output directory if it doesn't already exist
237277
238- # Open video
239- cap = cv2 .VideoCapture (input_video )
240- frame_width = 640
241- frame_height = 480
242- cap .set (cv2 .CAP_PROP_FRAME_WIDTH ,frame_width )
243- cap .set (cv2 .CAP_PROP_FRAME_HEIGHT ,frame_height )
244- #frame_width = int(round(cap.get(cv2.CAP_PROP_FRAME_WIDTH)))
245- #frame_height = int(round(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
246- print ("camera" ,input_video ," (" ,frame_width ,"," ,frame_height ,")" )
247-
248278
249279for i in range (nb_blaze_pipelines ):
250280 blaze = blaze_pipelines [i ]["blaze" ]
@@ -389,6 +419,11 @@ def ignore(x):
389419 if not (type (frame ) is np .ndarray ):
390420 print ("[ERROR] cv2.imread('woman_hands.jpg') FAILED !" )
391421 break ;
422+ elif bInputImage :
423+ frame = cv2 .imread (args .input )
424+ if not (type (frame ) is np .ndarray ):
425+ print ("[ERROR] cv2.imread(" ,args .input ,") FAILED !" )
426+ break ;
392427 else :
393428 flag , frame = cap .read ()
394429 if not flag :
0 commit comments