import cv
capture=cv.CaptureFromCAM(0)
cv.NamedWindow("capture", cv.CV_WINDOW_AUTOSIZE)
fourcc = cv.CV_FOURCC('M','J','P','G')
fps = 25
w, h = 640, 480
stream = cv.CreateVideoWriter("test.avi", fourcc, fps, (w, h))
while True:
frame = cv.QueryFrame(capture)
cv.WriteFrame(stream, frame)
cv.ShowImage("capture", frame)
此代码仅保存视频,但无法打开带视频的框架