Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV Error- Assertion failed (dst.data == dst0.data) when converting to grayscale and background subtraction. Please help me! Thank you very much.

include "stdio.h"

include "openc\cv.h"

include "opencv\cxcore.h"

include "opencv\highgui.h"

define WIDTH 320

define HEIGHT 240

int main( int argc, char **argv ){

int key;
CvCapture *capture = NULL;
IplImage *frameImage;

IplImage *backgroundImage = cvCreateImage( cvSize(WIDTH, HEIGHT), IPL_DEPTH_8U, 1); IplImage *grayImage = cvCreateImage( cvSize(WIDTH, HEIGHT), IPL_DEPTH_8U, 1);
IplImage *differenceImage = cvCreateImage( cvSize(WIDTH, HEIGHT), IPL_DEPTH_8U, 1);

char windowNameCapture[]="Capture";
char windowNameDifference[]="Difference";

if(( capture = cvCreateCameraCapture(-1)) == NULL) {

printf( "カメラが見つかりません\n");

    return -1;
}

cvNamedWindow( windowNameCapture, CV_WINDOW_AUTOSIZE );
cvNamedWindow( windowNameDifference, CV_WINDOW_AUTOSIZE );

frameImage = cvQueryFrame( capture );

cvCvtColor( frameImage, backgroundImage, CV_BGR2GRAY );

while( 1 ){

        frameImage = cvQueryFrame( capture );

    cvCvtColor( frameImage, grayImage, CV_BGR2GRAY );

    cvAbsDiff( grayImage, backgroundImage, differenceImage );

if( (*differenceImage).origin == 0 ) {

   cvFlip( differenceImage, differenceImage, 0 );

}

cvShowImage( windowNameCapture, frameImage );

cvShowImage( windowNameDifference, differenceImage );

  key = cvWaitKey( 1 );
  if( key == 'q' ) {
   break;

} else if( key == 'b' ) {

   frameImage = cvQueryFrame( capture );

   cvCvtColor( frameImage, backgroundImage, CV_BGR2GRAY );

}

}

   cvReleaseCapture( &capture );

   cvReleaseImage( &backgroundImage );

   cvReleaseImage( &grayImage );

   cvReleaseImage( &differenceImage );


cvDestroyWindow( windowNameCapture );
cvDestroyWindow( windowNameDifference );
return 0;
}