FlannBasedMatcher返回不同的结果 [英] FlannBasedMatcher returning different results

查看:180
本文介绍了FlannBasedMatcher返回不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用OpenCV中的FlannBasedMatcher,使用相同的参数调用匹配器会得到不同的结果.有人可以建议我做错了吗?

Using the FlannBasedMatcher in OpenCV, I am getting different results calling the matcher with the same parameters. Can anyone suggest what I am doing wrong please?

下面的代码显示了我遇到的问题的一个最小示例-简化了我如何使用FlannBasedMatcher的代表-这不是真正的代码:)

The code below shows a minimal example of the problem I am having - it is simplified representative of how I use the FlannBasedMatcher - this isn't real code :)

每次循环输出的结果应该相同,但不相同.

Results output each time around the loop should be identical, but they are not.

    int const k = std::min(query_descriptors.rows,
                      std::min(train_descriptors.rows, 2));

    cv::Mat query_descriptors_original = query_descriptors.clone();
    cv::Mat train_descriptors_original = train_descriptors.clone();
    for (int loop=0; loop<2; ++loop)
    {
        cv::FlannBasedMatcher matcher;
        matcher.add(std::vector<cv::Mat>(1, train_descriptors));

        std::vector<matches_t> knnMatches;
        matcher.knnMatch(query_descriptors,  knnMatches, k);

        matches.clear();
        for (auto const &knn : knnMatches)
        {
            matches.push_back(knn[0]);
            std::cout << knn[0].queryIdx << ',' << knn[0].trainIdx << '\n';
        }
        std::cout << '\n';

        assert(cv::countNonZero(query_descriptors != query_descriptors_original) == 0);
        assert(cv::countNonZero(train_descriptors != train_descriptors_original) == 0);
    }
}

虽然我认为输出不会有帮助(?),但输出是

The output, although I don't think it will help(?), is

0,27
1,170
2,100
3,100
4,123
5,100
6,191
7,71
8,191
9,67
10,27
11,45
12,302
13,190
14,248
15,158
16,262
17,248
18,211
19,67
20,248
21,275

0,2
1,200
2,224
3,302
4,130
5,302
6,191
7,195
8,191
9,195
10,200
11,45
12,248
13,277
14,248
15,255
16,262
17,248
18,182
19,14
20,54
21,284

推荐答案

FLANN在随机kd树算法和分层k均值树算法之间进行选择,以实现最佳的最近邻居近似.算法的选择基于几个因素,例如数据集结构和搜索精度.每种算法还具有一组会影响搜索性能的参数.

FLANN chooses between the randomized kd-tree algorithm and the hierarchical k-means tree algorithm to make the optimal nearest neighbors approximation. The choice of algorithm is based on several factors such as dataset structure and search precision. Each algorithm also has a set of parameters that effects the search performance.

这意味着它使用随机函数进行匹配,这就是为什么每次都得到不同结果的原因;)

That means that it uses a random function to match, thats why you get different results each time ;)

这篇关于FlannBasedMatcher返回不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆