cv2.VideoCapture不返回帧 [英] cv2.VideoCapture doesn't return frames

查看:540
本文介绍了cv2.VideoCapture不返回帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用wx按钮保存网络摄像头视频. 这是我的代码

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)

但是它会打印Capture Failed,直到我自己关闭python shell.因此,我想capture.read()不会返回帧.可能是什么原因?

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 :)

推荐答案

在读取捕获内容之前尝试初始化计数器 例如:

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"

这篇关于cv2.VideoCapture不返回帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆