Bartłomiej 'furas' Burek
furas.pl
# prywatne notatki - Python, Linux, Machine Learning, etc.

Python: use cv2 to create movie from images

Simple script which gets as argument pattern like path/*.jpg.

It uses pattern (instead path) with glob.glob() to get filenames, and uses cv2 to load images, resize them save as frame in video.

import cv2
import glob

# for test only 
#sys.argv += ['images/dot-*.jpg']

# get arguments
pattern = sys.argv[1]

# get filenames and sort them 
image_list = glob.glob(pattern)
image_list.sort()
#print(image_list)

# size for video and for all images 
size = (256, 256)

# create video writer with size (256, 256)
codec = cv2.VideoWriter_fourcc('X', 'V', 'I', 'D')
video = cv2.VideoWriter('./movieT.avi', codec, 20, size)

for img_name in image_list:
    img = cv2.imread(img_name)  # read image
    img = cv2.resize(img, size)  # image need the same size 
    video.write(img)  # write image in video 

video.release()
Książki: python-dla-kazdego-podstawy-programowania python-wprowadzenie python-leksykon-kieszonkowy python-receptury python-programuj-szybko-i-wydajnie python-projekty-do-wykorzystania black-hat-python-jezyk-python-dla-hackerow-i-pentesterow efektywny-python-59-sposobow-na-lepszy-kod tdd-w-praktyce-niezawodny-kod-w-jezyku-python aplikacje-internetowe-z-django-najlepsze-receptury