【问题标题】:cv2.VideoCapture doesn't return framescv2.VideoCapture 不返回帧
【发布时间】:2016-07-19 09:33:51
【问题描述】:

我正在尝试使用 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() 不会返回帧。可能是什么原因?

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

【问题讨论】:

  • 它是否在开头打印“错误”?
  • 不,我不打印错误它只打印capture failed

标签: python opencv wxpython video-capture raspberry-pi2


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 2020-03-12
    • 1970-01-01
    • 2018-04-29
    • 2021-04-26
    • 1970-01-01
    • 2021-12-20
    相关资源
    最近更新 更多