学习OpenCV——KeyPoint Matching 优化方式

今天读Mastering OpenCV with Practical Computer Vision Projects 中的第三章里面讲到了几种特征点匹配的优化方式,在此记录。

在图像特征点检测完成后(特征点检测参考:学习OpenCV——BOW特征提取函数(特征点篇)),就会进入Matching  procedure。



1. OpenCV提供了两种Matching方式

• Brute-force matcher (cv::BFMatcher) 

• Flann-based matcher (cv::FlannBasedMatcher)

Brute-force matcher就是用暴力方法找到点集一中每个descriptor在点集二中距离最近的descriptor;

Flann-based matcher 使用快速近似最近邻搜索算法寻找(用快速的第三方库近似最近邻搜索算法

一般把点集一称为 train set (训练集)对应模板图像,

  • 18
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
The ratio test in OpenCV is a method for filtering out false matches in feature matching algorithms. In feature matching, keypoints are detected in two images and their descriptors are calculated. These descriptors are then matched to find corresponding keypoints in both images. However, some matches may be incorrect due to noise, occlusion, or other factors. The ratio test helps filter out these incorrect matches. It works by comparing the distance between the best and second-best matches for each keypoint. If the distance ratio is below a certain threshold, the match is considered correct. If the ratio is above the threshold, the match is discarded. The threshold value is typically set to 0.7, meaning that the distance to the second-best match should be at least 1.4 times greater than the distance to the best match. Here's an example code snippet for implementing the ratio test in OpenCV: ``` # detect keypoints and compute descriptors for both images kp1, des1 = detector.compute(img1, None) kp2, des2 = detector.compute(img2, None) # match descriptors using a matcher object matches = matcher.knnMatch(des1, des2, k=2) # apply ratio test to filter out false matches good_matches = [] for m, n in matches: if m.distance < 0.7 * n.distance: good_matches.append(m) ``` In this code, `detector` is a keypoint detector object and `matcher` is a descriptor matcher object. The `knnMatch` function returns a list of the two best matches for each descriptor in the first image (`des1`) with descriptors in the second image (`des2`). The ratio test is then applied to filter out false matches, and the remaining matches are stored in `good_matches`.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值