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

free山炮龙 2015-05-05 09:39:30
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 );(这里出现了问题)
...全文
3523 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sjgshujianguo 2019-06-11
  • 打赏
  • 举报
回复
https://blog.csdn.net/Winder_Sky/article/details/79380836
weixin_39255320 2018-12-02
  • 打赏
  • 举报
回复
需要对keypoints1,keypoints2手动分配内存
keypoints1.resize(100);
keypoints2.resize(100);
可能有人发现仍然会崩溃,这里需要注意的是如果特征点数大于你设置的最大容量(最大容量为100,但是特征点有500个)依然是会崩溃的
SaYon_ 2017-09-15
  • 打赏
  • 举报
回复
我这边是安卓调用的jni接口,打印LOG显示创建detector失败,走到下面detect函数那直接崩溃了。但是我按照上面大神们的方法都不管用。请教大神~~~~~~

void Feature::detectKeypoints(const Mat& image, std::vector<KeyPoint>& keypoints)
{
//http://bbs.csdn.net/topics/391029205 detect函数崩溃解决
assert(image.type() == CV_8UC1);
assert(!m_detectType.empty());

keypoints.clear();
initModule_nonfree();

m_detector = FeatureDetector::create(m_detectType);//SIFT
if (m_detector.empty()) {
LOGE("failed to create m_detector");
}
m_detector->detect(image, keypoints);
}
csulizhang 2017-03-29
  • 打赏
  • 举报
回复
1、你必须保证你的图片类型是image.type() == CV_8UC1,你可以在开始用assert(image.type() == CV_8UC1);处理异常 2、图片尽量采用灰度图,减少计算量 3、img类型是MAT,最好读图的时候用Mat Image = imread(ImagePath, CV_LOAD_IMAGE_GRAYSCALE); 试试看
lingtianyulong 2017-01-12
  • 打赏
  • 举报
回复
你好,我在使用过程中遇到了同样的问题,经查找资料,是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);
wicnd 2017-01-12
  • 打赏
  • 举报
回复
先对vector手动分配内存 回答非常正确。
晒月光的青蛙 2016-03-21
  • 打赏
  • 举报
回复
楼主最好能下载opencv的source code然后debug到opencv的代码里面去 我大概帮楼主看了一下这个opencv的实现,detect里面有些assert被触发了就会crash。 根据下面的code可以看到首先你的img1要不为空,其次image的type要是CV_8U。如果不是,要通过cvCvtColor转换

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)" );
chengchaoli 2016-03-15
  • 打赏
  • 举报
回复
不知道楼主解决没有。我也是和你一样的问题。我是编译的opencv3.1加上opencv_contrib这个库。其他的imread imshow这些都能用,也能这样定义Ptr<xfeatures2d::SURF> detector = xfeatures2d::SURF::create(1000); detector, 但是运行detector->detect(image1, keypoints);这一句时程序就崩溃了。

4,445

社区成员

发帖
与我相关
我的任务
社区描述
图形图像/机器视觉
社区管理员
  • 机器视觉
  • 迪菲赫尔曼
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧