Unhandled exception using cvCanny
I am implementing cvCanny for a segmetation/edge detection project for my image processing class. The program runs multiple segmentation algorithms via command line arguments, and passes the input image to the corresponding algorithm via IplImage*. You can see in the code below, I am taking the pointer passed to the function, and creating a local copy to do the work on.
void CannyEdgeSeg (IplImage * image, int)
{ const char* name = "Edge Detection Window"; // Kernel size int N = 7;
// Set up images
IplImage* img;
img = cvCloneImage(image);
IplImage* img_b = cvCreateImage( cvSize(img->width+N-1,img->height+N-1), img->depth, img->nChannels );
IplImage* out = cvCreateImage( cvGetSize(img_b), IPL_DEPTH_8U, img_b->nChannels );
// Add convolution boarders
CvPoint offset = cvPoint((N-1)/2,(N-1)/2);
cvCopyMakeBorder(img, img_b, offset, IPL_BORDER_REPLICATE, cvScalarAll(0));
// Make window
cvNamedWindow( name, 1 );
// Edge Detection Variables
int aperature_size = N;
double lowThresh = 20;
double highThresh = 40;
// Create trackbars
cvCreateTrackbar( "High", name, &high_switch_value, 4, switch_callback_h );
cvCreateTrackbar( "Low", name, &low_switch_value, 4, switch_callback_l );
switch_callback_h(0);
switch_callback_l(0);
for(;;) {
switch( highInt ){
case 0:
highThresh = 200;
break;
case 1:
highThresh = 400;
break;
case 2:
highThresh = 600;
break;
case 3:
highThresh = 800;
break;
case 4:
highThresh = 1000;
break;
}
switch( lowInt ){
case 0:
lowThresh = 0;
break;
case 1:
lowThresh = 100;
break;
case 2:
lowThresh = 200;
break;
case 3:
lowThresh = 400;
break;
case 4:
lowThresh = 600;
break;
}
// Edge Detection
cvCanny( img_b, out, lowThresh*N*N, highThresh*N*N, aperature_size );
cvShowImage(name, out);
if( cvWaitKey( 15 ) == 27 )
break;
}
// Release
cvReleaseImage( &img );
cvReleaseImage( &img_b );
cvReleaseImage( &out );
cvDestroyWindow( name );
};
However, with this methodology, I get this error once it tries to run cvCanny:
Unhandled exception at 0x000007fefd899e5d in Project2.exe: Microsoft C++ exception: cv::Exception at memory location 0x0012f630..
But, if I explicitly call the image to read in my function, rather than using the passed image,
IplImage* img = cvLoadImage("fruits.jpg", 0);
the application runs just fine.
I don't understand why it would matter if the image is passed or called explicitly in the function. I was able to usethis exact same method, creating a clone of the passed image, in my other segmentation algorightms without any issues. Is there something specific to cvCanny that I am miss? Any help here would be greatly appreciated. Thanks.