2016-07-19 105 views
1

我试图用wx按钮保存摄像头视频。 这是我的代码cv2.VideoCapture不返回帧

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

我该如何让它工作?希望对一些专家的意见:)

+0

它打印“错误”的开始? – Micka

+0

不,我不打印错误只打印'捕获失败' – SivamNatesan

回答

0

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

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

感谢它的工作:) – SivamNatesan