我的代码:
video = cv2.VideoWriter(name, 0, 1, size)
for image in frames:
video.write(image)
video.release()
name
是描述文件名的字符串,大小是(360, 640)
,frames是包含所有图像(具有所有颜色值的ndarray)的列表。当我尝试运行此代码时,它将返回TypeError: Expected Ptr<cv::UMat> for argument 'image'
这是什么意思,我该如何解决此错误?编辑:
我的代码现在是:
fourcc = cv2.VideoWriter_fourcc(*'XVID')
video = cv2.VideoWriter('mosaic.avi', fourcc, 30, size)
for image in frames:
video.write(np.float32(image))
video.release()
它不会返回任何错误,但是视频已损坏。
最佳答案
UMat是透明API(TAPI)的一部分,有助于为CPU和OpenCL实现编写一个代码。
您可以通过以下方法纠正此错误:
video = cv2.VideoWriter(name, 0, 1, size)
for image in frames:
video.write(cv2.UMat(image))
video.release()
要么Import numpy as np
video = cv2.VideoWriter(name, 0, 1, size)
for image in frames:
image = np.array(image)
video.write(image)
video.release()
关于python - 使用OpenCV和Python从图像创建视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62882680/