find_feature_matches(img1,img2,keypoints_1,keypoints_2,matches)函数

find_feature_matches

vector<KeyPoint> keypoints_1,keypoints_2;
vector<DMatch> matches;
find_feature_matches(img1,img2,keypoints_1,keypoints_2,matches);
  1. 定义
void find_feature_matches ( const Mat& img1, const Mat& img2,
    						vector<KeyPoint>& kp1,
	  						vector<KeyPoint>& kp2,
	    					vector<DMatch>& matches)
{
  Mat dp1,dp2;
  Ptr<FeatureDetector> detector = ORB::create();
  Ptr<DescriptorExtractor> descriptor = ORB::create();
  Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce-Hamming");

  detector->detect (img1, kp1);
  detector->detect (img2, kp2);

  descriptor->compute( img1, kp1, dp1);
  descriptor->compute( img2, kp2, dp2);

  vector<DMatch> match;
  matcher->match( dp1, dp2, match);

  double min_d = 10000,max_d = 0;

  for (int i = 0; i < dp1.rows; ++i) {
    double dist = match[i].distance;
	if(dist < min_d) min_d = dist;
	if(dist > max_d) max_d = dist;
  }

  printf("max dist : %f \n",max_d);
  printf("min dist : %f \n",min_d);

  for (int i =0; i < dp1.rows;++i) {
    if (match[i].distance <= max( 2*min_d, 30.0 ))
	  matches.push_back(match[i]);
  }

}
  1. KeyPoint类
//默认构造函数
CV_WRAP KeyPoint():pt(0,0),size(0),angle(-1),response(0),octave(0),class_id(-1){}

//pt(x,y):关键点坐标
//size():该关键点邻域直径大小
//angle:角度,表示关键点的方向,值为【0,360】,负值表示不使用
//response:响应强度
//octave:从哪一层金字塔得到的关键点
//class_id:当要对图片进行分类时,用class_id对每个关键点进行区分,默认为-1
关于keypoints_1[0],keypoints_2[0],matches[]:
keypoints_1[0]:存储图一的第0个特征点,不一定与keypoints_2[0]对应
keypoints_2[0]:存储图二的第0个特征点,不一定与keypoints_2[0]对应
matches[0]:存储某一特征点的信息,图一中第matches.queryIdx个特征点与图二中第matches.trainIdx个特征点是相互对应的,matches.distance是两个对应特征点之间的距离。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值