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
#include

4.测试程序:

Mat img1_sc1, img2_sc1;
cvtColor(img1, img1_sc1, COLOR_RGB2GRAY);
cvtColor(img2, img2_sc1, COLOR_BGR2GRAY);
vector keypoints_1, keypoints_2;
Ptr  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;
vectormatchcs;
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);

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

你可能感兴趣的:(计算机视觉,opencv)