openCv 中的边缘检测给出运行时错误
我使用 cvCanny 函数来检测边缘。
cvCanny( img_b, out, lowThresh*N*N, highThresh*N*N, aperature_size );
但在运行时它会给出运行时错误。错误消息根本不清楚。它指的是一些内存位置。请帮我..!!
代码:
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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您非常接近完成这项工作。基本上,这是您的问题:
cvShowImage
时显示,而是在您调用cvWaitKey
时显示。那时您已经释放了图像,因此不会显示任何内容。CvCapture
加载的帧。该文档明确表示不这样做:image_b
或out
。它们甚至没有在您发布的代码中声明。 我不知道你的代码是如何编译的,更不用说运行了。image_b
指定为精明边缘检测的源,而实际上它应该是frame
就像我说的那样,许多微小的点。这是有效的代码:
编译:
标准图像和输出:
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_b
orout
anywhere. They're not even declared in the code you posted. I don't know how your code even compiled, let alone ran.image_b
as the source to the canny edge detection, when it should really beframe
Like I said, a number of tiny points. Here's code that works:
Compiles with:
Standard image and output: