社区首页 > 机器学习 > opencv的FeatureD...

opencv的FeatureDetector,请问当运行到它的detect函数时,程序会崩溃是什么原因?

来自: 伱丶蕞紾匮

回复量:5

创建时间: 2017-03-29 15:56


 initModule_nonfree();//初始化模块,使用SIFT或SURF时用到

Ptr<FeatureDetector> detector = FeatureDetector::create("SIFT");//创建SIFT特征检测器

    Ptr<DescriptorExtractor> descriptor_extractor = DescriptorExtractor::create( "SIFT" );//创建特征向量生成器

    Ptr<DescriptorMatcher> descriptor_matcher = DescriptorMatcher::create( "BruteForce" );//创建特征匹配器

    if( detector.empty() || descriptor_extractor.empty() )

        cout<<"fail to create detector!";

   //读入图像

    IplImage * img1 = cvLoadImage("phone2.jpg");

    IplImage * img2 = cvLoadImage("phone3.jpg");


//特征点检测

    double t = getTickCount();//当前滴答数

    vector<KeyPoint> keypoints1,keypoints2;

    detector->detect( img1, keypoints1 );(这里出现了问题)


0

5 回复

随心所欲 1F 2017-03-29 16:19:30

不知道楼主解决没有。我也是和你一样的问题。我是编译的opencv3.1加上opencv_contrib这个库。其他的imread  imshow这些都能用,也能这样定义Ptr<xfeatures2d::SURF> detector = xfeatures2d::SURF::create(1000);  detector,

但是运行detector->detect(image1, keypoints);这一句时程序就崩溃了。


回复 赞(
韩小野ooo 2F 2017-03-29 17:36:38

楼主最好能下载opencv的source code然后debug到opencv的代码里面去

我大概帮楼主看了一下这个opencv的实现,detect里面有些assert被触发了就会crash。

根据下面的code可以看到首先你的img1要不为空,其次image的type要是CV_8U。如果不是,要通过cvCvtColor转换


回复 赞(
韩小野ooo 3F 2017-03-29 17:38:12

if( image.empty() || image.depth() != CV_8U )
        CV_Error( Error::StsBadArg, "image is empty or has incorrect depth (!=CV_8U)" );
 
 if( !mask.empty() && mask.type() != CV_8UC1 )
        CV_Error( Error::StsBadArg, "mask has incorrect type (!=CV_8UC1)" );


回复 赞(
你的温柔,我明白 4F 2017-03-29 20:56:40

你好,我在使用过程中遇到了同样的问题,经查找资料,是vector析构引起的,只要在opencv 函数调用前,先对vector手动分配内存即可,我的问题是这样解决的,具体的问题,还得具体分析:

double t = getTickCount();//当前滴答数  

vector<KeyPoint> keypoints1, keypoints2;

keypoints1.resize(100);

keypoints2.resize(100);

  detector->detect(img1, keypoints1);//检测img1中的SIFT特征点,存储到keypoints1中  

  detector->detect(img2, keypoints2);

//detector.detect(img1, keypoints1);


回复 赞(
足球小子 5F 2017-03-30 11:22:13

先对vector手动分配内存

回答非常正确。


回复 赞(
发表回复