FlannBasedMatcher立体匹配
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
FlannBasedMatcher⽴体匹配#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/nonfree/nonfree.hpp>
#include<opencv2/legacy/legacy.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( )
{
//【0】改变console字体颜⾊
system("color 4F");
//【1】载⼊源图⽚
Mat img_1 = imread("1.jpg", 1 );
Mat img_2 = imread( "2.jpg", 1 );//【2】利⽤SURF检测器检测的关键点
int minHessian = 300;
SURF detector( minHessian );
std::vector<KeyPoint> keypoints_1, keypoints_2;
detector.detect( img_1, keypoints_1 );
detector.detect( img_2, keypoints_2 );
//【3】计算描述符(特征向量)
SURF extractor;
Mat descriptors_1, descriptors_2;
pute( img_1, keypoints_1, descriptors_1 );
pute( img_2, keypoints_2, descriptors_2 );
//【4】采⽤FLANN算法匹配描述符向量
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_1, descriptors_2, matches );
double max_dist = 0; double min_dist = 100;
//【5】快速计算关键点之间的最⼤和最⼩距离
for( int i = 0; i < descriptors_1.rows; i++ )
{
double dist = matches[i].distance;
if( dist < min_dist ) min_dist = dist;
if( dist > max_dist ) max_dist = dist;
}
//输出距离信息
printf("> 最⼤距离(Max dist) : %f \n", max_dist );
printf("> 最⼩距离(Min dist) : %f \n", min_dist );
//【6】存下符合条件的匹配结果(即其距离⼩于2* min_dist的),使⽤radiusMatch同样可⾏
std::vector< DMatch > good_matches;
for( int i = 0; i < descriptors_1.rows; i++ )
{
if( matches[i].distance < 2*min_dist )
{ good_matches.push_back( matches[i]); }
}
//【7】绘制出符合条件的匹配点
Mat img_matches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
//【8】输出相关匹配点信息
for( int i = 0; i < good_matches.size(); i++ )
{ printf( ">符合条件的匹配点 [%d] 特征点1: %d -- 特征点2: %d \n", i, good_matches[i].queryIdx, good_matches[i].trainIdx ); } //【9】显⽰效果图
imshow( "匹配效果图", img_matches );
//按任意键退出程序
waitKey(0);
return0;
}。