下面是一个适用于Windows (original)的示例:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XDIV')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while(True):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
out.write(frame)
cv2.imshow('frame',gray)
if cv2.waitKey(0) & 0xFF == ord('q'):
break
cap.release()
out.release()
cv2.destroyAllWindows()
在Linux程序提供:
AttributeError: 'module' object没有属性'VideoWriter_fourcc'
我没有尝试,但这应该工作:
fourcc = cv2.cv.CV_FOURCC(*'XVID')