您好,我正在开发识别模式的 Android 应用程序,如您所见,它可以正常工作,但我不得不面对过度匹配的问题。我读到这是因为我的匹配器太敏感了。为了匹配,我使用这种匹配器:
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
...
matcher.match(descriptor1, descriptorLogo, matches);
我也尝试实现 knnmatch()
但这是因为我无法使用函数 Features2d.drawMatches()
感谢您的回答,希望能解决我的问题
最佳答案
有几种技术可以去除异常值或优化匹配:
交叉检查
比率测试
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... :(
}
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])
{
}
}
关于android - 如何减少 OpenCV 模式识别中的匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8118825/