我试图用 numpy 数组创建视频,但出现错误
I was trying to create a video out of a numpy array but i was getting an error
我试图从 NumPy 数组创建视频,但我一直收到此错误:
cv2.error: OpenCV(4.2.0) c:\projects\opencv-python\opencv\modules\imgproc\src\color.simd_helpers.hpp:94: error: (-2:Unspecified error) in function '__thiscall cv::impl::`anonymous-namespace'::CvtHelper<struct cv::impl::`anonymous namespace'::Set<3,4,-1>,struct cv::impl::A0xe227985e::Set<3,4,-1>,struct cv::impl::A0xe227985e::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)'
> Unsupported depth of input image:
> 'VDepth::contains(depth)'
> where
> 'depth' is 4 (CV_32S)
Link 到完整代码 - https://drive.google.com/file/d/1qqat43eJw0Ql46TlFRiGMjqROs2QjCFj/view?usp=sharing
代码结构如下:
import cv2 , time , numpy
frame = numpy.asarray(the long list of NumPy array, if you want, it is in the link above)
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('output.mp4v' , fourcc , 20.0 , (640 , 480))
out.write(frame)
out.release()
如果我在它之前添加一个 frame = frame.astype(numpy.uint8) ,然后创建了一个视频,但它实际上是第一帧只有一张照片的视频!!!!
请帮我解决这个问题。这真的意味着很多。
我只能在您的 link 中找到一张 RGB 图像。您想用尺寸为 640x480x3 的单个图像制作视频吗?如果能保证这里的frame数组有多个RGB图片,下面的代码应该就够了:
import cv2 , time , numpy
frame = numpy.asarray(the long list of NumPy array, if you want, it is in the link above)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
writer = cv2.VideoWriter('output.avi', fourcc, 1, (frame_height, frame_width))
i=0
for img in (frame):
print("writing frame # {}".format(i))
writer.write(img.astype('uint8'))
i+=1
writer.release()
我试图从 NumPy 数组创建视频,但我一直收到此错误:
cv2.error: OpenCV(4.2.0) c:\projects\opencv-python\opencv\modules\imgproc\src\color.simd_helpers.hpp:94: error: (-2:Unspecified error) in function '__thiscall cv::impl::`anonymous-namespace'::CvtHelper<struct cv::impl::`anonymous namespace'::Set<3,4,-1>,struct cv::impl::A0xe227985e::Set<3,4,-1>,struct cv::impl::A0xe227985e::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)'
> Unsupported depth of input image:
> 'VDepth::contains(depth)'
> where
> 'depth' is 4 (CV_32S)
Link 到完整代码 - https://drive.google.com/file/d/1qqat43eJw0Ql46TlFRiGMjqROs2QjCFj/view?usp=sharing
代码结构如下:
import cv2 , time , numpy
frame = numpy.asarray(the long list of NumPy array, if you want, it is in the link above)
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('output.mp4v' , fourcc , 20.0 , (640 , 480))
out.write(frame)
out.release()
如果我在它之前添加一个 frame = frame.astype(numpy.uint8) ,然后创建了一个视频,但它实际上是第一帧只有一张照片的视频!!!!
请帮我解决这个问题。这真的意味着很多。
我只能在您的 link 中找到一张 RGB 图像。您想用尺寸为 640x480x3 的单个图像制作视频吗?如果能保证这里的frame数组有多个RGB图片,下面的代码应该就够了:
import cv2 , time , numpy
frame = numpy.asarray(the long list of NumPy array, if you want, it is in the link above)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
writer = cv2.VideoWriter('output.avi', fourcc, 1, (frame_height, frame_width))
i=0
for img in (frame):
print("writing frame # {}".format(i))
writer.write(img.astype('uint8'))
i+=1
writer.release()