opencv3/C++ FLANN特征匹配方式
使用函数detectAndCompute()检测关键点并计算描述符
函数detectAndCompute()参数说明:
voiddetectAndCompute( InputArrayimage,//图像 InputArraymask,//掩模 CV_OUTstd::vector&keypoints,//输出关键点的集合 OutputArraydescriptors,//计算描述符(descriptors[i]是为keypoints[i]的计算描述符) booluseProvidedKeypoints=false//使用提供的关键点 );
match()从查询集中查找每个描述符的最佳匹配。
参数说明:
voidmatch( InputArrayqueryDescriptors,//查询描述符集 InputArraytrainDescriptors,//训练描述符集合 CV_OUTstd::vector&matches,//匹配 InputArraymask=noArray()//指定输入查询和描述符的列表矩阵之间的允许匹配的掩码 )const;
FLANN特征匹配示例:
#include#include usingnamespacecv; usingnamespacecv::xfeatures2d; //FLANN对高维数据较快 intmain() { Matsrc1,src2; src1=imread("E:/image/image/card2.jpg"); src2=imread("E:/image/image/cards.jpg"); if(src1.empty()||src2.empty()) { printf("canontloadimages....\n"); return-1; } imshow("image1",src1); imshow("image2",src2); intminHessian=400; //选择SURF特征 Ptr detector=SURF::create(minHessian); std::vector keypoints1; std::vector keypoints2; Matdescriptor1,descriptor2; //检测关键点并计算描述符 detector->detectAndCompute(src1,Mat(),keypoints1,descriptor1); detector->detectAndCompute(src2,Mat(),keypoints2,descriptor2); //基于Flann的描述符匹配器 FlannBasedMatchermatcher; std::vector matches; //从查询集中查找每个描述符的最佳匹配 matcher.match(descriptor1,descriptor2,matches); doubleminDist=1000; doublemaxDist=0; for(inti=0;i maxDist) { maxDist=dist; } if(dist goodMatches; for(inti=0;i (),DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS); imshow("output",matchesImg); waitKey(); return0; }
以上这篇opencv3/C++FLANN特征匹配方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。