0

why do i keep receiving this error when i use cvIntegral()

if ((image = cvLoadImage(filename,1))==0){ 
return -1;//if there is something wrong exit with -1
   }

image2 = cvCreateImage(cvSize(image->width++,image->height++),IPL_DEPTH_8U,1);

cvIntegral(image, image2, NULL,NULL);
cvReleaseImage(&image);//release image and exit
cvReleaseImage(&image2);//release image and exit

return 0;

this is the error

OpenCV Error: Assertion failed (sum.data == sum0.data && sqsum.data == sqsum0.data && tilted.data == tilted0.data) in cvIntegral, file /build/buildd/opencv-2.3.1/modules/imgproc/src/sumpixels.cpp, line 306 terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.3.1/modules/imgproc/src/sumpixels.cpp:306: error: (-215) sum.data == sum0.data && sqsum.data == sqsum0.data && tilted.data == tilted0.data in function cvIntegral

sgarizvi
  • 16,623
  • 9
  • 64
  • 98
938752641
  • 3
  • 1

1 Answers1

2

cvIntegral expects the output image to be of type CV_32F or CV_64F. Also, the number of channels for the source and destination images should be same. You should be doing this:

image2 = cvCreateImage(cvSize(image->width+1,image->height+1),IPL_DEPTH_32F,image->nChannels);
sgarizvi
  • 16,623
  • 9
  • 64
  • 98
  • thanks, but i have tried that but keep getting same error OpenCV Error: Assertion failed (sum.data == sum0.data && sqsum.data == sqsum0.data && tilted.data == tilted0.data) in cvIntegral, file /build/buildd/opencv-2.3.1/modules/imgproc/src/sumpixels.cpp, line 306 terminate called after throwing an instance of 'cv::Exception' what(): /build/buildd/opencv-2.3.1/modules/imgproc/src/sumpixels.cpp:306: error: (-215) sum.data == sum0.data && sqsum.data == sqsum0.data && tilted.data == tilted0.data in function cvIntegral – 938752641 Mar 29 '13 at 07:45
  • Are you sure you are not doing `image->width++`. You should do `image->width+1` and `image->height+1`. Also, the number of channels should be same for `image` and `image2`. You will get the exception if the number of channels are different. Check the updated code in my answer. – sgarizvi Mar 29 '13 at 08:06
  • i tried it again with image->height+1 and image->width+1 same error : – 938752641 Mar 29 '13 at 08:09
  • I tried the code. The actual reason is the number of channels. Keep them same. I also get the same exception if number of channels are different. – sgarizvi Mar 29 '13 at 08:11