Created
March 28, 2018 17:54
-
-
Save NickShargan/925db35499ef6b5f8e421ae74a4adf35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
video_path = "./vid.mp4" | |
cap = cv2.VideoCapture(video_path) | |
target_shape = (640, 360) | |
fgbg = cv2.bgsegm.createBackgroundSubtractorMOG() | |
if not cap.isOpened(): | |
print("error opening video stream") | |
while (cap.isOpened()): | |
ret, frame = cap.read() | |
print(frame.shape) | |
if ret: | |
frame = cv2.resize(frame, target_shape, interpolation=cv2.INTER_CUBIC) | |
fg_mask = fgbg.apply(frame) | |
fg_mask = cv2.cvtColor(fg_mask, cv2.COLOR_GRAY2BGR) | |
stacked_frame = np.concatenate((frame, fg_mask), axis=0) | |
cv2.imshow('frame', stacked_frame) | |
if cv2.waitKey(30) & 0xFF == ord('q'): | |
break | |
else: | |
break | |
cv2.destroyAllWindows() | |
cap.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment