1

嘿,我试图在当前帧与前一帧之间进行减法运算,(附加的代码)代码正在运行,但我得到错误和灰色窗口而没有结果我在命令提示符下得到的错误:

编译器未对齐堆栈变量。Libavcodec 已被错误编译,可能非常缓慢或崩溃。这不是 libavcodec 中的错误,而是编译器中的错误。您可以尝试使用 gcc >= 4.2 重新编译。不要向 FFmpeg 开发人员报告崩溃。OpenCV 错误:断言失败 (src1.size() == dst.size() && src1.type() == dst.type()) 在未知函数中,文件 ........\ocv\opencv\ src\cxcore\cxarithm.cpp ,第 1563 行。

有人有想法吗?请你的帮助!谢谢你

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;

}

4

1 回答 1

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.

于 2012-04-05T11:33:13.427 回答