I'm trying to record a video using cv2.VideoWriter but my frames are only 2 channels rather than 3 or 4, as the error describes. How can I fix the frames so that they are able to be part of a video?
Here's the guts of my function:
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
The image is showing, but when it reaches out.write, it spits out this error:
error: /tmp/opencv20150506-38415-u2kidu/opencv-
2.4.11/modules/imgproc/src/color.cpp:3650:
error:(-215) scn == 3 || scn == 4 in function cvtColor
I know that my image is 2 channels, and I need it to be 3 or 4 channels, but I don't know how to fix it.