简体   繁体   中英

Creating a video from images using OpenCV with Python

My code:

video = cv2.VideoWriter(name, 0, 1, size)

for image in frames:
    video.write(image)

video.release()

name is a string describing the filename, size is (360, 640) and frames is a list containing all the images (ndarrays with all the color values). When I try to run this code, it returns

TypeError: Expected Ptr<cv::UMat> for argument 'image'

What does that mean and how do I fix this error?

Edit: My code is now:

fourcc = cv2.VideoWriter_fourcc(*'XVID')
video = cv2.VideoWriter('mosaic.avi', fourcc, 30, size)

for image in frames:
    video.write(np.float32(image))

video.release()

It does not return any errors, however the video is corrupted.

UMat is a part of the Transparent API (TAPI) than help to write one code for the CPU and OpenCL implementations. You can correct this error by following methods:

video = cv2.VideoWriter(name, 0, 1, size)

for image in frames:
    video.write(cv2.UMat(image))

video.release()

Or

Import numpy as np
video = cv2.VideoWriter(name, 0, 1, size)

for image in frames:
    image = np.array(image)
    video.write(image)

video.release()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM