I have a series of images in *.tif format that I want to use to create a video. I am using OpenCV 3.1.0 in Python 2.7. Below is a snippet of my code:
import cv2
import numpy as np
nIMAGES = 10
files = glob.glob(DIR + '\\' + tpname +'\\*.tif' )
image_stack = np.empty((500, 220, nIMAGES))
mov = DIR + '\\' + tpname + '\\' + tpname + '_mov.avi'
MOV = cv2.VideoWriter(filename=mov, fourcc=cv2.VideoWriter_fourcc('F', 'M', 'P', '4'), fps=2, frameSize=(220, 500)) # frame size is 220 x 500
for i in np.arange(0, nIMAGES):
print 'Working on: ' + files[i][-14:-4]
image = cv2.imread(files[i], 0)
crop_image = image[50:550, 252:472] #crop y:h, x:w
# now let's create the movie:
crop_image = cv2.applyColorMap(crop_image, cv2.COLORMAP_JET)
MOV.write(crop_image)
MOV.release()
When I run this code, I create an AVI file that is 0 Kb (it hasn't saved anything to it).
I believe I am missing something like frame = cv2.VideoCapture.read(crop_image)
in which case I would convert the write line to MOV.write(frame)
. However, I get an AttributeError
in that the VideoCapture.read
is not an attribute.
I am using this OpenCV webpage as my guide: http://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html