views:

34

answers:

1

I'm trying to process each frame in a pair of video files in OpenCV and then write the resulting frames to an output avi file. Everything works, except that the output video file looks strange: instead of one solid image, the image is repeated three times and horizontally compressed so all three copies fit into the window. I suspect there is something going wrong with the number of channels the writer is expecting, but I'm giving it 8-bit single channel images to write. Below are the setting with which I'm initializing my videowriter:

  //Initialize the video writer
  CvVideoWriter *writer = cvCreateVideoWriter("out.avi",CV_FOURCC('D','I','V','X'), 30, frame_sizeL, 0);

Has anyone encountered this strange output from the openCV videowriter before? I've been checking the resulting frames with cvSaveImage just to see if somehow my processing step is creating the "tripled" image, but it's not. It's only when I write to the output avi with cvWriteFrame that the image gets "tripled" and compressed.

Edit: So I've discovered that this only happens when I attempt to write single channel images using write frame. If I write 3 channel 8-bit RGB images, the output video turns out fine. Why is it doing this? I am correctly passing "0" for the color argument when initializing the CvVideoWriter, so it should be expecting single channel images.

A: 

In the C++ version you have to tell cv::VideoWriter that you are sending a single channel image by setting the last paramter "false", are you sure you are doing this?

Martin Beckett
I believe so. The last argument for cvCreateVideoWriter tells whether or not to expect color images. I am definitely passing a 0 to the last argument as seen here:cvCreateVideoWriter("out.avi",CV_FOURCC('D','I','V','X'), 30, frame_sizeL, 0);The function header for the cvCreatevideoWriter is as follows:typedef struct CvVideoWriter CvVideoWriter CvVideoWriter* cvCreateVideoWriter(const char* filename, int fourcc, double fps, CvSize frame_size, int is_color=1)Should I be using the c++ style syntax for setting up the video writer rather than the c style functions?
Shoot I just noticed that the documentation says "(the flag is currently supported on Windows only)". I'm using linux, so does this mean there's no way to get the videoWriter to accept grayscale images?
Obviuous solution is to make a 3C grayscale image by simply putting the same value into the RGB channels.Most video formats expect RGB (or HSV) rather than single channel
Martin Beckett
Thanks, that worked! :)