1

hey i tried to do subtraction between current frame to previous, (the code attached ) the code running but i get errors and gray window without result the errors i got on command prompt:

Compiler did not align stack variables. Libavcodec has been miscompiled and may be very slow or crash. This is not a bug in libavcodec, but in the compiler. You may try recompiling using gcc >= 4.2. Do not report crashes to FFmpeg developers. OpenCV Error: Assertion failed (src1.size() == dst.size() && src1.type() == dst. type()) in unknown function, file ........\ocv\opencv\src\cxcore\cxarithm.cpp , line 1563.

someone have an idea? please your help!! thank you

int main()  
{  


int key = 0; 




 CvCapture* capture = cvCaptureFromAVI( "macroblock.mpg" ); 
 IplImage* frame = cvQueryFrame( capture );
 IplImage* currframe = cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,1);
 IplImage* destframe = cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,1);

    if ( !capture ) 

{  
    fprintf( stderr, "Cannot open AVI!\n" );  
    return 1;  
    }

  int fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );

  cvNamedWindow( "dest", CV_WINDOW_AUTOSIZE );

  while( key != 'x' )
      {
          frame = cvQueryFrame( capture );
     currframe = cvCloneImage( frame );// copy frame to current
     frame = cvQueryFrame( capture );// grab frame
   cvSub(frame,currframe,destframe);// subtraction between the last frame to cur

          if(key==27 )break;
          cvShowImage( "dest",destframe);
           key = cvWaitKey( 1000 / fps );
           }  
       cvDestroyWindow( "dest" );
       cvReleaseCapture( &capture );
       return 0;

}

vgonisanz
  • 11,831
  • 13
  • 78
  • 130
Ilan Reuven
  • 61
  • 2
  • 3
  • 6

1 Answers1

3

The problem is here

IplImage* currframe = cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,1);
IplImage* destframe = cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,1);

What you are doing is that you are reading off an mpeg that has 3 channels per frame. Now when you do the subtraction, you subtract a 3 channel frame from a 1 channel frame. This WILL cause problems. Try setting the number of channels to 3. And see if it works

IplImage* currframe = cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,3);
IplImage* destframe = cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,3);

To be sure, check the number of channels for the queried image, the cloned image. And since you are pushing the final image into a destination image of 1 channel. There you are corrupting the data. If no exception is thrown/caught at any place.

OpenCV Error: Assertion failed (src1.size() == dst.size() && src1.type() == dst. type()) 

Assertion failed seems to be a clear indicator of what I have explained.