使用opencv 2.4.1 anaconda python 2.7创建视频

时间:2016-11-30 06:36:38

标签: python opencv anaconda

import cv2

img1 = cv2.imread('1.jpg')

img2 = cv2.imread('2.jpg')

img3 = cv2.imread('3.jpg')

height , width , layers =  img1.shape

fourcc = cv2.cv.CV_FOURCC(*'XVID')

video = cv2.VideoWriter('videococo.avi',fourcc,1,(width,height))

cv2.VideoWriter(img1)

cv2.VideoWriter(img2)

cv2.VideoWriter(img3)

cv2.destroyAllWindows()

video.release()

这是我的python代码,当我运行它时

给我TypeError:必需参数' fourcc' (位置2)未找到

有时它会给我带0KB的视频而不是打开文件。

1 个答案:

答案 0 :(得分:0)

您需要将代码修改为:

import cv2
img1 = cv2.imread('1.jpg')
img2 = cv2.imread('2.jpg')
img3 = cv2.imread('3.jpg')

height , width , layers =  img1.shape     
fps=20
video = cv2.VideoWriter("videococo.avi", cv.CV_FOURCC(*'DIVX'), fps, (img1.shape[1], img1.shape[0]))
video.write(img1)
video.write(img2)
video.write(img3)


video.release()

在您的代码中,您正在创建“视频”对象,但却尝试以静态方式访问它,因此您的fourcc参数未被读取