I have used cvCanny function to detect Edges.
cvCanny( img_b, out, lowThresh*N*N, highThresh*N*N, aperature_size );
But in run time it gives runtime error. The error msg not clear at all. It refers some memory location. Please help me..!!
code:
void switch_callback_h( int position ){
highInt = position;
}
void switch_callback_l( int position ){
lowInt = position;
}
int _tmain(int argc, _TCHAR* argv[])
{
const char* name = "Edge Detection Window";
// Kernel size
int N = 7;
CvCapture* capture = cvCaptureFromCAM(1);
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
// Add convolution boarders
CvPoint offset = cvPoint((N-1)/2,(N-1)/2);
cvCopyMakeBorder(frame, 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 );
highThresh = 800;
lowThresh = 100;
cvCanny( img_b, out, lowThresh*N*N, highThresh*N*N, aperature_size );
cvShowImage(name, out);
cvReleaseImage( &frame );
cvReleaseImage( &img_b );
cvReleaseImage( &out );
cvDestroyWindow( name );
if( cvWaitKey( 15 ) == 27 )
break;
return 0;
}
You were very close to making this work. Basically, here are your problems:
cvShowImage, but when you callcvWaitKey. By that time you’ve already freed the image, so nothing will be shown.CvCapture. The documentation explicitly says not to do this:image_boroutanywhere. They’re not even declared in the code you posted. I don’t know how your code even compiled, let alone ran.image_bas the source to the canny edge detection, when it should really beframeLike I said, a number of tiny points. Here’s code that works:
Compiles with:
Standard image and output: