剛剛接觸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
.
.
.
.