当前位置:   article > 正文

opencv(4.5.5) 运行surf算法报错,但可运行sift_the function/feature is not implemented) this algo

the function/feature is not implemented) this algorithm is patented and is e

报错:

 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. 源程序增加头文件:

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

4.测试程序:

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/81143
推荐阅读
相关标签
  

闽ICP备14008679号