Skip to content

Instantly share code, notes, and snippets.

@non117 non117/cv.py
Created Jan 2, 2015

Embed
What would you like to do?
cvで背景差分
# -*- coding: utf-8 -*-
import cv2
def main():
cap = cv2.VideoCapture(0)
#cap = cv2.VideoCapture('opatan.mp4')
ret, frame = cap.read()
if not ret:
return
width = len(frame[0])
height = len(frame)
fourcc = cv2.cv.CV_FOURCC('m','p','4','v')
out = cv2.VideoWriter('output.mp4', fourcc, 10, (width, height), True)
fgbg = cv2.BackgroundSubtractorMOG2()
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frame = fgbg.apply(frame)
#out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(10) > 0:
break
cap.release()
out.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.