Issues with using VideoWriter on opencv python

asked 2014-10-09 06:50:37 -0600

pamparana gravatar image

updated 2014-10-09 07:14:07 -0600

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 "", line 35, in <module>
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"], fourcc, int(fps), (int(width), int(height)),True)

while (video.isOpened()):
    ret, frame =
    # This simply takes the frame and does some image processing on it
    segments = compute_superpixels(frame, num_pixels=100)
    processed = mark_boundaries(frame, segments)

Does anyone have any idea what I might be doing wrong here? I am on Mac OSX.

I tried something which might shed some light (or not). So, if I want to write the original frame i.e. replace




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'>
edit retag flag offensive close merge delete