打开CV Python-摄像头捕获视频

时间:2015-04-15 07:33:31

标签: python opencv video

我正在使用下面的代码,但是我得到了一个大小为0B的视频output.avi。如何设置/定义参数(视频的持续时间)以获得正确的输出?我打算使用获得的视频进行进一步处理。

import numpy as np
import cv2

cap = cv2.VideoCapture(0)


#Define the codec and create VideoWriter object
w=int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH ))
h=int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT ))
fourcc = cv2.cv.CV_FOURCC(*'DIVX')
out = cv2.VideoWriter('output.avi', fourcc, 25, (w,h))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)

        # write the flipped frame
        out.write(frame)

        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()

0 个答案:

没有答案