2016-07-19 220 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

相關問題