SURF角点检测出现错误:SURF.exe 中的 0x756ad36f 处未处理的异常: Microsoft C++ 异常: 内存位置 0x003fcaf0 处的 cv::Exception。

来源:互联网 发布:淘宝怎么买分期手机 编辑:程序博客网 时间:2024/05/18 18:00

        今天用了一下SURF角点检测的程序,结果在调试过程中总出现错误:SURF.exe 中的 0x756ad36f 处未处理的异常: Microsoft C++ 异常: 内存位置 0x003fcaf0 处的 cv::Exception。

代码:

 int main()
{
        Mat  image, image1= imread ( "test.jpg");
cvtColor ( image1, image, CV_BGR2GRAY);
vector<KeyPoint> keypoints;
SurfFeatureDetector surf(2500);
surf.detect (image, keypoints);
drawKeypoints( image, keypoints, image, Scalar::all(255), DrawMatchesFlags::DEFAULT);
namedWindow("surf", CV_WINDOW_AUTOSIZE);
imshow("surf",  image);
waitKey();
return 0;
}

后来发现,调试出现错误是因为,当加载图片不成功时,无返回值,所以出现内存错误。

解决方法:在cvtColor前面加上代码

if(image1.empty())
{
          fprintf(stderr, "Can not load image ");
  return -1;
}

这样就可以了。

原创粉丝点击