Skip to content

Instantly share code, notes, and snippets.

@sagi-z
Last active December 22, 2016 13:41
Show Gist options
  • Save sagi-z/4ed32d90f0b84ecef1418b2ffb6b005a to your computer and use it in GitHub Desktop.
Save sagi-z/4ed32d90f0b84ecef1418b2ffb6b005a to your computer and use it in GitHub Desktop.
import numpy as np
import cv2
import bgsubcnt # 1. New import
# A temporary solution to OpenCV 3.1.0 bug
# with background subtractors
cv2.ocl.setUseOpenCL(False)
cap = cv2.VideoCapture('/home/userName/Downloads/opencv-3.1.0/samples/data/768x576.avi')
fgbg = bgsubcnt.createBackgroundSubtractor() # 2. New background subtractor
while(1):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
fgmask = fgbg.apply(gray)
cv2.imshow('frame',fgmask)
k = cv2.waitKey(30)
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment