0

I am reading a avi file, and do some background subtrcation work. The wierd thing is when I use cvRetrieveFrame, I got a strange image, like below:

origin:

enter image description here

cvRetrieveFrame returns:

enter image description here

I don't know what's the problem. Here is my code snippet.

CvCapture* readerAvi = cvCaptureFromAVI( filename.c_str() );
if(readerAvi == NULL)
{
    std::cerr << "Could not open AVI file." << std::endl;
return 0;
}

// retrieve information about AVI file
cvQueryFrame(readerAvi); //....get some information, width, height, ....

// grad next frame from input video stream
if(!cvGrabFrame(readerAvi))
{         
    std::cerr << "Could not grab AVI frame." << std::endl;
    return 0;
}       
frame_data = cvRetrieveFrame(readerAvi);
hakunami
  • 2,351
  • 4
  • 31
  • 50
  • At first sight it looks like you've got the red and blue channels swapped - i.e. BGR instead of RGB or vice versa. – Roger Rowland May 06 '13 at 08:34
  • @RogerRowland what about the offset? look at the image right part, it should be in the left. – hakunami May 06 '13 at 08:53
  • I see - it looks like the frame has a header of a different size to expected, so it's maybe a pixel format problem or a codec issue. Can you post the code you use to display the image after `cvRetrieveFrame`? – Roger Rowland May 06 '13 at 09:07
  • I noticed you call `cvQueryFrame` first - this wraps `cvGrabFrame` and `cvRetrieveFrame` internally, so you'll skip a frame with this code. Remember that the data returned by `cvRetrieveFrame` is re-used for the next frame, so you have to `cvClone` it if you want a copy of that image. – Roger Rowland May 06 '13 at 09:11
  • Take a look at this related answer - http://stackoverflow.com/a/4568840/2065121 – Roger Rowland May 06 '13 at 09:12
  • @RogerRowland I don't show the image. The second image is saved as a bmp fils from cvRetrieveFrame returns. – hakunami May 06 '13 at 09:24

0 Answers0