Skip to content

Commit

Permalink
[update] get the video from a webcam
Browse files Browse the repository at this point in the history
  • Loading branch information
sthanhng committed Oct 18, 2018
1 parent 7abbced commit 5de6217
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions YOLO.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,26 @@ def close_session(self):


def detect_video(model, video_path=None, output=None):
vid = cv2.VideoCapture(video_path)
if video_path == 'stream':
vid = cv2.VideoCapture(0)
else:
vid = cv2.VideoCapture(video_path)

if not vid.isOpened():
raise IOError("Couldn't open webcam or video")

# The video format and fps
video_fourcc = int(vid.get(cv2.CAP_PROP_FOURCC))
# video_fourcc = int(vid.get(cv2.CAP_PROP_FOURCC))
video_fourcc = cv2.VideoWriter_fourcc('M', 'G', 'P', 'G')
video_fps = vid.get(cv2.CAP_PROP_FPS)

# The size of the frames to write
video_size = (int(vid.get(cv2.CAP_PROP_FRAME_WIDTH)),
int(vid.get(cv2.CAP_PROP_FRAME_HEIGHT)))
isOutput = True if output != "" else False
if isOutput:
out = cv2.VideoWriter(output, video_fourcc, video_fps, video_size)
output_fn = 'output_video.avi'
out = cv2.VideoWriter(os.path.join(output, output_fn), video_fourcc, video_fps, video_size)

accum_time = 0
curr_fps = 0
Expand Down
6 changes: 3 additions & 3 deletions yoloface_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def get_args():
help='image detection mode')
parser.add_argument('--video', type=str, default='samples/subway.mp4',
help='path to the video')
parser.add_argument('--output', type=str,
default='', help='image/video output path')
parser.add_argument('--output', type=str, default='outputs/',
help='image/video output path')
args = parser.parse_args()
return args

Expand Down Expand Up @@ -55,7 +55,7 @@ def _main():
else:
print('[i] ==> Video detection mode\n')
# Call the detect_video method here
detect_video(YOLO(args), args.video)
detect_video(YOLO(args), args.video, args.output)

print('Well done!!!')

Expand Down

0 comments on commit 5de6217

Please sign in to comment.