我使用opencv打开视频,逐帧处理并将其写回视频。对于某些视频,这种方法很好,但对于其他人来说,当我尝试将帧写回视频时,我收到了这个有线错误:
cv2.error: /home/xxx/Documents/opencv_videos/opencv/modules/videoio/src/cap_mjpeg_encoder.cpp:829: error: (-215) img.cols == width && img.rows == height && channels == 3 in function write
以下是我的代码:
cap = cv2.VideoCapture('cut.avi')
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
out = cv2.VideoWriter('output.avi',fourcc, 25.0, (1280,720))
count = 0
while(cap.isOpened()):
ret, frame = cap.read()
if ret == True:
processed_frame = PROCESS(frame)
cv2.imwrite('temp.jpg',processed_frame)
out.write(processed_frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
但是,我可以使用cv2.imwrite
将进程帧写入磁盘上的jpeg映像。有谁知道这个错误来自哪里?谢谢!