cv2.VideoCapture doesn't return frames

*爱你&永不变心* 提交于 2019-12-13 20:00:07

问题


I am trying to save a webcam video with wx Buttons. This is my code

def OnRecord(self, evt):
    capture = cv2.VideoCapture(0)
    if (not capture.isOpened()):
       print "Error"

    # video recorder
    fourcc = cv2.cv.CV_FOURCC('D', 'I', 'V', 'X')  # cv2.VideoWriter_fourcc() does not exist
    out = cv2.VideoWriter("output.avi", fourcc, 9.0, (640, 480), True)

    # record video
    while (capture.isOpened()):
        ret, frame = capture.read()
        if not ret:
            print "Capture Failed"
        else:
            out.write(frame)
            cv2.imshow('Video', frame)

But it prints Capture Failed until i close the python shell myself. So, i guess capture.read() doesn't returns frames. What might be the reason?

How can i make it work? Hope for some expert advice :)


回答1:


Try initialize counter before reading the capture for Eg:

i = 0
while i < 0:
     ret, frame = capture.read()
     if ret:
          out.write(frame)
     else:
          print "Error"


来源:https://stackoverflow.com/questions/38454655/cv2-videocapture-doesnt-return-frames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!