OpenCV Create Video From Array Of Images in Python
The following code can be used to generate video from image array in openCV. How many seconds you want an image to stay on the screen, you have to add that much of the image. For example, image 1 will wait for 4 seconds on the screen, while image 2 will wait for 1 second.
import cv2
frames = [cv2.imread('image1.jpg'),
cv2.imread('image1.jpg'),
cv2.imread('image1.jpg'),
cv2.imread('image1.jpg'),
cv2.imread('image2.jpg')]
height, width, _ = frames[0].shape
out = cv2.VideoWriter('output.avi', cv2.VideoWriter_fourcc(*'DIVX'), 1, (width, height))
[out.write(f) for f in frames]
out.release()
Comments
Post a Comment