Search on blog:

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)

# 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 


Problem z wczytaniem pliku haarcascades w OpenCV

Czasami tutorial wczytuje plik haarcascades zainstalowany z OpenCV w ten sposób

eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')

ale gdy my uruchamiamy taki kod

import numpy as np
import cv2

eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')

image = np.array([1,2,3], dtype='uint8')
eye_cascade.detectMultiScale(img, 1.3, 5)

to otrzymujemy błąd …

« Page: 1 / 1 »