Skip to content

Instantly share code, notes, and snippets.

@mmitou
Created December 3, 2015 09:33
Show Gist options
  • Select an option

  • Save mmitou/16f5d4781d708ce62a57 to your computer and use it in GitHub Desktop.

Select an option

Save mmitou/16f5d4781d708ce62a57 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import cv2
cap = cv2.VideoCapture(0)
substractor = cv2.createBackgroundSubtractorMOG2()
while(True):
succeeded, frame = cap.read()
if not succeeded:
continue
fgmask = substractor.apply(frame)
fg = cv2.bitwise_and(frame, frame, mask = fgmask)
cv2.imshow('fg', fg)
cv2.imshow('frame', frame)
cv2.imshow('mask', fgmask)
if cv2.waitKey(1) & 0xFF == ord(' '):
break
cap.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment