-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathvideo_demo.py
More file actions
30 lines (26 loc) · 746 Bytes
/
video_demo.py
File metadata and controls
30 lines (26 loc) · 746 Bytes
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
import cv2
from visualize_cv2 import model, display_instances, class_names
import sys
args = sys.argv
if(len(args) < 2):
print("run command: python video_demo.py 0 or video file name")
sys.exit(0)
name = args[1]
if(len(args[1]) == 1):
name = int(args[1])
stream = cv2.VideoCapture(name)
while True:
ret , frame = stream.read()
if not ret:
print("unable to fetch frame")
break
results = model.detect([frame], verbose=1)
# Visualize results
r = results[0]
masked_image = display_instances(frame, r['rois'], r['masks'], r['class_ids'],
class_names, r['scores'])
cv2.imshow("masked_image",masked_image)
if(cv2.waitKey(1) & 0xFF == ord('q')):
break
stream.release()
cv2.destroyWindow("masked_image")