python - cv2.VideoCapture 不返回帧

标签 python opencv wxpython video-capture raspberry-pi2

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

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() 不会返回帧。可能是什么原因?

我怎样才能让它发挥作用?希望得到一些专家的建议:)

最佳答案

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

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

关于python - cv2.VideoCapture 不返回帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38454655/

相关文章:

c++ - 如何计算 OpenCV 中矩阵的直方图?

Python GUI 在整个过程完成之前不会更新

python - 用于检查 Python 是否已安装的 Powershell 脚本

c - 警告 : incompatible implicit declaration of built-in function 'lrint'

c++ - pytorch C++与alexnet和cv::imread图像

wxpython - 如何使用wxpython绘制垂直线

python - wxPython : GDI ressources are not release after wxFrame. 销毁()

javascript - 如何在不同的窗口中实现 oauth 进程,然后重新加载调用者窗口

python - 矩阵类方法中的参数错误 - Python

python - 如何更快地计算 nltk plaintextcorpus 中的单词?