- Fetch all the image file names using glob
- Read all the images using cv2.imread()
- Store all the images into a list
- Create a VideoWriter object using cv2.VideoWriter()
- Save the images to video file using cv2.VideoWriter().write()
- Release the VideoWriter and destroy all windows.
Let’s see the code
import numpy as np
img_array = 
for filename in glob.glob('C:/New folder/Images/*.jpg'):
img = cv2.imread(filename)
height, width, layers = img.shape
size = (width,height)
out = cv2.VideoWriter('project.avi',cv2.VideoWriter_fourcc(*'DIVX'), 15, size)
for i in range(len(img_array)):
glob.glob(Pathname) fetches all the filenames present in that path. ‘*.jpg’ means all the jpg files. So, in code glob.glob() fetches the filename of all the jpg files present in that path.
Hope you enjoy reading.
If you have any doubt/suggestion please feel free to ask and I will do my best to help or improve myself. Good-bye until next time.