Skip to main content

OpenCV Create Video From Array Of Images

 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

Popular posts from this blog

OpenCV Crop an image in Python

 Crop operation in OpenCV is very simple. You should first read the image. Then the values x, y, h, w must be determined to specify the region to be cropped. You can do this using the code below. import cv2 image = cv2.imread( 'image.jpg' ) y= 10 x= 20 h= 200 w= 250 crop = image[y:y+h , x:x+w] cv2.imshow( 'Image' , crop) cv2.waitKey( 0 )

OpenCV Drawing a Line

How To Draw a Line In OpenCV Python? To draw a line, we need to select the starting and ending coordinates of the line. First, let's create a black image and draw a green line. We need to use the code below to create a black image: image = np.zeros(( 360 , 360 , 3 ) , np.uint8) Now we can create our line. cv2.line(image , ( 0 , 0 ) , ( 511 , 511 ) , ( 0 , 255 , 0 ) , 5 ) The code for creating a line is as follows: import numpy as np import cv2 image = np.zeros(( 360 , 360 , 3 ) , np.uint8) cv2.line(image , ( 0 , 0 ) , ( 511 , 511 ) , ( 0 , 255 , 0 ) , 5 ) cv2.imshow( "image" , image) cv2.waitKey( 0 ) cv2.destroyAllWindows() Output: Another Example import numpy as np import cv2 image = np.zeros(( 360 , 360 , 3 ) , np.uint8) cv2.line(image , ( 0 , 180 ) , ( 360 , 180 ) , ( 0 , 255 , 0 ) , 5 ) cv2.imshow( "image" , image) cv2.waitKey( 0 ) cv2.destroyAllWindows() Output:

Opencv Image Properties - rows, columns and channels, type of image data, number of pixels

Opencv Image Properties  OpenCV allows access to image properties. These properties are rows, columns and channels, type of image data, number of pixels. The img.shape command is used to access the shape of the image. Returns rows, columns and channels. import  cv2 img = cv2.imread( 'flower.jpg' ) print (img.shape) Result: (400, 400, 3) The data type of the image is obtained with img.dtype import cv2 img = cv2.imread( 'flower.jpg' ) print (img.dtype) Result: uint8