如何减少OpenCV模式识别中的匹配?

Csa*_*abi 3 android opencv

在此输入图像描述

嗨,我正在开发识别模式的Android应用程序,它正如你所见,但我必须面对过度匹配的问题.我已经读过它是因为我的匹配器过于敏感而引起的.为了匹配我使用这种匹配:

DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
Run Code Online (Sandbox Code Playgroud)

...

matcher.match(descriptor1, descriptorLogo, matches);
Run Code Online (Sandbox Code Playgroud)

我也尝试实现,knnmatch()但它是reault我无法用该功能绘制Features2d.drawMatches()

谢谢你的任何答案,希望它能解决我的问题

Jav*_*ock 5

有几种技术可以删除异常值或改进匹配:

  • 交叉检查

  • 比率测试

  • RANSAC +平面形状的同形

我通常应用最后两个.

比率测试:

BFMatchermatcher(CV_L2);
vector<vector<DMatch>>nearest_neighbors;
matcher.radiusMatch(
right_points_to_find_flat,
right_features_flat,
nearest_neighbors,
2.0f);

// Check that the found neighbors are unique (throw away neighbors
//  that are too close together, as they may be confusing)
std::set<int>found_in_right_points; // for duplicate prevention
for(inti=0;i<nearest_neighbors.size();i++) {
DMatch _m;
if(nearest_neighbors[i].size()==1) {
    _m = nearest_neighbors[i][0]; // only one neighbor
} else if(nearest_neighbors[i].size()>1) {
        // 2 neighbors – check how close they are
        double ratio = nearest_neighbors[i][0].distance / nearest_neighbors[i][1].distance;
if(ratio < 0.7) { // not too close
    // take the closest (first) one
    _m = nearest_neighbors[i][0];
} else { // too close – we cannot tell which is better
        continue; // did not pass ratio test – throw away
}
} else {
        continue; // no neighbors... :(
}
Run Code Online (Sandbox Code Playgroud)

RANSAC +单应:

std::vector<Point2f> object;
  std::vector<Point2f> scene;

  for( int i = 0; i < good_matches.size(); i++ )
  {
    //-- Get the keypoints from the good matches
    object.push_back( keypoints_object[ good_matches[i].queryIdx ].pt );
    scene.push_back( keypoints_scene[ good_matches[i].trainIdx ].pt );
  }
  Mat H = findHomography( object, scene, CV_RANSAC, status );

  //draw only the matches considered inliers by RANSAC => status=1
  for(i=0;i=object.size();i++){
  if(status[i])
  {
  }
  }
Run Code Online (Sandbox Code Playgroud)