我尝试使用cv2.VideoWriter录制视频,但我的帧只有2个频道而不是3或4,正如错误所描述的那样。如何修复帧以使它们能够成为视频的一部分?
这是我职能的胆量:
video = cv2.VideoCapture('Video.mp4')
fourcc = cv2.cv.CV_FOURCC('D', 'I', 'V', 'X')
out = cv2.VideoWriter("video.mov", int(fourcc), int(get_framerate(video)), (int(get_width(video)), int(get_height(video))), 0)
while(video.isOpened()):
ret, frame = video.read()
if (ret == True):
grayframe = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
ret, final_frame = cv2.threshold(grayframe, 65, 255, cv2.THRESH_BINARY)
cv2.imshow("frame", final_frame)
out.write(final_frame)
else:
break
if cv2.waitKey(10) == 27:
cv2.destroyAllWindows()
break
video.release()
out.release()
return
图像正在显示,但是当它到达out.write时,它会吐出这个错误:
error: /tmp/opencv20150506-38415-u2kidu/opencv-
2.4.11/modules/imgproc/src/color.cpp:3650:
error:(-215) scn == 3 || scn == 4 in function cvtColor
我知道我的图片是2个频道,我需要3个或4个频道,但我不知道如何修复它。