刚刚接触python 所以有点不太熟
有上网查了一下做法
我的程式码如下
import cv
import os, glob,sys
path = 'C:\image\'
video = cv.CreateVideoWriter('output.avi',-1 , 10,(2456,2936), 1)
for infile in glob.glob( os.path.join(path, '*.jpg') ):
img = cv.LoadImage(infile)
cv.WriteFrame(video, img)
del video
但是这样合成出来的影片大小都是0kb 是哪里做错了吗?
另外 要读图片是不是只能用opencv里的涵式读? (ex:cv.LoadImage)
而不能用PIL里的Image.open
麻烦大家了
============================================================
谢谢大家帮忙
重写一次 给之后有需要的人
安装opencv-python :
opencv-python-2.4.8.win32-py2.7.exe (http://ppt.cc/8-Cs)
(没安装 codec 要安装一下)
import cv
import os, glob
impath = 'C:/image/' # image path
Fname = 'output.avi' # output file name
FPS = 10
CODE_TYPE = cv.CV_FOURCC('X','V','I','D') # 注一
Fsize = (height,width) #frame size
video = cv.CreateVideoWriter(Fname, CODE_TYPE, FPS, Fsize, is_color = 1)
for infile in glob.glob( os.path.join(impath, '*.jpg') ):
img = cv.LoadImage(infile)
cv.WriteFrame(video, img)
del video
注一
CODE_TYPE = 0 => no compression
CODE_TYPE = -1 => jump out a msgbox asking for the compress formate
=======================================
CODE_TYPE = cv.CV_FOURCC(X,X,X,X)
=======================================
cv.CV_FOURCC('H','F','Y','U') # HuffYUV
cv.CV_FOURCC('D','R','A','C') # BBC Dirac
cv.CV_FOURCC('X','V','I','D') # MPEG-4 Part 2
cv.CV_FOURCC('X','2','6','4') # MPEG-4 Part 10 (aka. H.264 or AVC)
cv.CV_FOURCC('M','P','1','V') # MPEG-1 video
.
.
.
.