【问题标题】:OpenCV and DAISY descriptorsOpenCV 和 DAISY 描述符
【发布时间】:2016-02-10 16:04:33
【问题描述】:

我正在尝试使用 DAISY 和 FlannBasedMatcher 在同一图像的两个视角之间进行特征匹配。

我认为没有一个匹配项是正确的。

注意:每次运行程序时我也会得到不同的结果,但我认为这是预期的行为,如下所述:FlannBasedMatcher returning different results

那么我做错了什么?为什么这些比赛如此糟糕?


输入图像

错误和不确定的结果

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/xfeatures2d.hpp>

#include <iostream>
#include <vector>
#include <stdio.h>

using namespace cv;
using std::vector;

const float nn_match_ratio = 0.7f;      // Nearest neighbor matching ratio
const float keypoint_diameter = 15.0f;

int main(int argc, char ** argv){

    // Load images
    Mat img1 = imread(argv[1]);
    Mat img2 = imread(argv[2]);

    vector<KeyPoint> keypoints1, keypoints2;

    // Add every pixel to the list of keypoints for each image
    for (float xx = keypoint_diameter; xx < img1.size().width - keypoint_diameter; xx++) {
        for (float yy = keypoint_diameter; yy < img1.size().height - keypoint_diameter; yy++) {
            keypoints1.push_back(KeyPoint(xx, yy, keypoint_diameter));
            keypoints2.push_back(KeyPoint(xx, yy, keypoint_diameter));
        }
    }

    Mat desc1, desc2;

    Ptr<cv::xfeatures2d::DAISY> descriptor_extractor = cv::xfeatures2d::DAISY::create();

    // Compute DAISY descriptors for both images 
    descriptor_extractor->compute(img1, keypoints1, desc1);
    descriptor_extractor->compute(img2, keypoints2, desc2);

    vector <vector<DMatch>> matches;

    // For each descriptor in image1, find 2 closest matched in image2 (note: couldn't get BF matcher to work here at all)
    FlannBasedMatcher flannmatcher;
    flannmatcher.add(desc1);
    flannmatcher.train();
    flannmatcher.knnMatch(desc2, matches, 2);


    // ignore matches with high ambiguity -- i.e. second closest match not much worse than first
    // push all remaining matches back into DMatch Vector "good_matches" so we can draw them using DrawMatches
    int                 num_good = 0;
    vector<KeyPoint>    matched1, matched2; 
    vector<DMatch>      good_matches;

    for (int i = 0; i < matches.size(); i++) {
        DMatch first  = matches[i][0];
        DMatch second = matches[i][1];

        if (first.distance < nn_match_ratio * second.distance) {
            matched1.push_back(keypoints1[first.queryIdx]);
            matched2.push_back(keypoints2[first.trainIdx]);
            good_matches.push_back(DMatch(num_good, num_good, 0));
            num_good++;
        }
    }

    Mat res;
    drawMatches(img1, matched1, img2, matched2, good_matches, res);
    imwrite("_res.png", res);

    return 0;
}

【问题讨论】:

  • 很难说,但我建议尝试使用另一个描述符,看看是否能得到更好的结果?
  • 我尝试了 SURF 而不是 DAISY 并且在那里也得到了奇怪的结果 - 包括明亮区域和黑暗区域之间的匹配。至少对于 SURF,每次都是相同的结果。不过感谢您的指导,我会看看是否可以重现 openCV SURF 示例并从那里开始工作。

标签: opencv feature-detection feature-extraction flannbasedmatcher


【解决方案1】:

我怎样才能得到两个图像中匹配的坐标,即第一图像中匹配的坐标和第二图像中匹配的坐标?

【讨论】:

    【解决方案2】:

    对不起。我发现了我的错误。我在以下行中反转了索引:

            matched1.push_back(keypoints1[first.queryIdx]);
            matched2.push_back(keypoints2[first.trainIdx]);
    

    【讨论】:

    • 这个例子的正确代码是什么?我试过你的例子,但它不起作用。
    • 改为.. keypoints1[first.trainIdx] 和 keypoints2[first.queryIdx]。
    猜你喜欢
    • 1970-01-01
    • 2010-10-27
    • 2018-06-28
    • 1970-01-01
    • 2017-03-21
    • 2014-07-15
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多