I need to create a video out of sequence of images in python. I found this code online that works fine but I am having a small problem with the ordering of the images when being read in python. Even though the ordering in the folder is ok. E.x frame100.jpg , frame101.jpg , frame102.jpg,....., frame1000, frame1001, .... when I read them with python inside the loop , after debuging I see the following 'frame100.jpg', 'frame1000.jpg', 'frame1001.jpg', 'frame1002.jpg',.....,frame101,frame1010 , frame1011....
This is the code
def images_to_video():
image_folder = 'data_out'
images = [img for img in os.listdir(image_folder) if img.endswith(".jpg")]
frame = cv2.imread(os.path.join(image_folder, images[0]))
height, width, layers = frame.shape
video = cv2.VideoWriter('project.avi',cv2.VideoWriter_fourcc(*'DIVX'), 15, (width,height))
for image in images:
video.write(cv2.imread(os.path.join(image_folder, image)))
cv2.destroyAllWindows()
video.release()