解决方法——AttributeError: 'module' object has no attribute 'VideoWriter_fourcc'

今天遇到的AttributeError: 'module' object has no attribute 'VideoWriter_fourcc'

错误出现的原因是你安装的版本和你使用的语句可能不对应。


后来经过查询得知:cv2.VideoWriter_fourcc()是opencv3.0所用,而cv2.cv.CV_FOURCC()用于opencv2.4.*



cv2.VideoWriter_fourcc is for opencv3.0. with opencv2.4, use cv2.cv.CV_FOURCC()


but try 'M','J','P','G' or some other combination for the codec



let's make it a bit clearer:

3.0 version:

out = cv2.VideoWriter('output.avi',cv2.VideoWriter_fourcc(*'XVID'), 20.0, (640,480))

2.4 version:

out = cv2.VideoWriter('output.avi',cv2.cv.CV_FOURCC('M','J','P','G'), 20.0, (640,480))
berak gravatar image berak  (Jan 2 '15)
上方答案出自——AttributeError: 'module' object has no attribute 'VideoWriter_fourcc' - OpenCV Q&A Forum  http://answers.opencv.org/question/29648/attributeerror-module-object-has-no-attribute-videowriter_fourcc/

你可能感兴趣的:(opencv_python)