4

我一直在尝试使用 opencv 将视频制作模块添加到我的程序中,但我可能无法让视频显示超过 1 帧。我在搜索答案时得到了这个示例代码(在 python 中使用 OpenCV 2.4.0 创建视频

import cv2
from cv import *

img1 = cv2.imread('i001.png')
img2 = cv2.imread('i002.png')
img3 = cv2.imread('i003.png')

height , width , layers =  img1.shape

video=cv2.VideoWriter('test.avi', CV_FOURCC('D', 'I', 'V', 'X'),1,(width,height))

video.write(img1)
video.write(img2)
video.write(img3)

cv2.destroyAllWindows()
video.release()

这将创建一个运行 3 秒的视频,但在所有 3 秒内仅显示第一个图像。是编解码器错误还是我遗漏了什么?

4

1 回答 1

0

你可以使用:

 cv.WriteFrame(writer, image)

像这样 :

 import cv

 img1 = cv.LoadImage('i001.png')
 img2 = cv.LoadImage('i002.png')
 img3 = cv.LoadImage('i003.png')

 writer=cv.CreateVideoWriter(filename, fourcc, fps, frame_size, is_color)

 cv.WriteFrame(writer, img1)
 cv.WriteFrame(writer, img2)
 cv.WriteFrame(writer, img3)

还看:

http://opencv.willowgarage.com/documentation/python/highgui_reading_and_writing_images_and_video.html?highlight=createvideowriter#CreateVideoWriter

于 2013-06-12T11:31:23.970 回答