I have been trying to get the openCV python VideoWriter object to work with no success. What I am trying to do is read a video, grab the frame, do some processing and write it back to a video file. The error that I get is:
Traceback (most recent call last):
File "detect.py", line 35, in <module>
out_video.write(processed)
cv2.error: /tmp/opencv-z9Pa/opencv-2.4.9/modules/imgproc/src/color.cpp:4419:
error: (-215) src.depth() == dst.depth() in function cvCvtColor
The code I wrote is as follows:
video = VideoCapture(args["video"])
num_frames = video.get(CV_CAP_PROP_FRAME_COUNT)
width = video.get(CV_CAP_PROP_FRAME_WIDTH)
height = video.get(CV_CAP_PROP_FRAME_HEIGHT)
fps = video.get(CV_CAP_PROP_FPS)
out_video = VideoWriter()
fourcc = CV_FOURCC('m', 'p', '4', 'v')
out_video.open(args["out"], fourcc, int(fps), (int(width), int(height)),True)
while (video.isOpened()):
ret, frame = video.read()
# This simply takes the frame and does some image processing on it
segments = compute_superpixels(frame, num_pixels=100)
processed = mark_boundaries(frame, segments)
out_video.write(processed)
Does anyone have any idea what I might be doing wrong here?
I tried something which might shed some light (or not). So, if I want to write the original frame i.e. replace
out_video.write(processed)
with
out_video.write(frame)
I get my original video back. However, the frame and processed object have the same size and type! So, now I am completely baffled as to what is going on. The output of processed and frame shape and types are:
frame: (576, 720, 3)
processed: (576, 720, 3)
frame: <type 'numpy.ndarray'>
processed: <type 'numpy.ndarray'>