2015-09-20 39 views
0

我是Jeong Won Kyoung。我有一個嚴肅的問題給你。當像這樣編碼時,我有這樣的警告信息。我的編碼有什麼問題? 'AttributeError'模塊'對象沒有屬性'VideoWriter fourcc''

編碼:

#coding utf-8 
import numpy as np 
import cv2 

cap = cv2.VideoCapture(0) 

#define the codec and create VideoWriter object 
fourcc = cv2.VideoWriter.fourcc('X','V','I','D') 
out = cv2.VideoWriter('output.avi',fource, 20, (640,480)) 

while(cap.isOpened()): 
    ret, frame = cap.read() 
    if ret==True: 
     frame = cv2.flip(frame,0) 

     #write the flipped frame 
     out.write(frame) 

     cv2.imshow('frame',frame) 
     if cv2.waitKey(1) & 0xFF == ord('q'): 
      break 

    else: 
     break 

#release everything if job is finishing 
cap.release() 
out.release() 
cv2.destroyAllWindows() 

And then I ran the module, I got this weird result. 

"Traceback (most recent call last) 
File"/home/pi/saving_a_video.py", line.8,in <module> 
    fourcc = cv2.VideoWriter_fourcc('X','V','I','D') 
AttributeError: 'module' object has no attribute 'VideoWriter fourcc" 
has appeared on other python window. 

我只是跟着從 「http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html」 這個編碼,然後,它沒有很好地工作。 如何更改此編碼'fourcc = cv2.VideoWriter_fourcc('X','V','I','D')'? 我該如何操作這個程序?

回答

1

你正在尋找的功能是cv2.VideoWriter_fourcc而不是cv2.VideoWriter.fourcc

+0

好。儘管我更改爲cv2.VideoWriter_fourcc,但操作不正常。 – JeongWonKyoung

+0

例外變化了嗎? – David

相關問題