opencv(4.5.5) 运行surf算法报错,但可运行sift

报错:

 Error: The function/feature is not implemented (This algorithm is patented and is excluded in this 

原因:专利原因,但sift在4.4.0版本及以后已可用,但surf仍不可用

解决:

若未安装过扩展模块或sift算法执行也报错,则先参考我的一篇博客:opencv配置环境吐血经验_Wsyoneself的博客-CSDN博客

1.cmake重新编译opencv:将OPENCV_ENABLE_NONFREE选中

重新:Configure->Generate->open project

2.重新生成install

CMakeTargets->INSTALL, 右键选择仅生成install

3. 源程序增加头文件:

#include<opencv2/xfeatures2d.hpp>
#include<opencv2/xfeatures2d/nonfree.hpp>

4.测试程序:

Mat img1_sc1, img2_sc1;
cvtColor(img1, img1_sc1, COLOR_RGB2GRAY);
cvtColor(img2, img2_sc1, COLOR_BGR2GRAY);
vector<KeyPoint> keypoints_1, keypoints_2;
Ptr <xfeatures2d::SURF> detector = xfeatures2d::SURF::create(250);//参数 hessianThreshold:默认100,关键点检测的阈值,越高监测的点越少
Mat descripotor_1, descriptor_2;
//特征检测并将图像的特征点放入对应的描述符中
detector->detectAndCompute(img1_sc1, Mat(), keypoints_1, descripotor_1);
detector->detectAndCompute(img2_sc1, Mat(), keypoints_2, descriptor_2);
//根据描述符进行最佳匹配:
BFMatcher matcher;
vector<DMatch>matchcs;
matcher.match(descripotor_1, descriptor_2, matchcs);
//展示匹配:
Mat img_matches;
drawMatches(img1_sc1, keypoints_1, img2_sc1, keypoints_2, matchcs, img_matches);
imshow("matches", img_matches);

(该算法的性能会慢一些,可以选择小一点的图像进行测试)

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值