找到匹配代码的好关键点

时间:2016-05-30 11:14:51

标签: c++ opencv image-processing orb

我在LATCH_match.cpp文件夹中的xfeature2D内找到了此代码:

BFMatcher matcher(NORM_HAMMING);
vector< vector<DMatch> > nn_matches;
matcher.knnMatch(desc1, desc2, nn_matches, 2);
vector<KeyPoint> matched1, matched2, inliers1, inliers2;
vector<DMatch> good_matches;
for (unsigned i = 0; i < matched1.size(); i++) {
    Mat col = Mat::ones(3, 1, CV_64F);
    col.at<double>(0) = matched1[i].pt.x;
    col.at<double>(1) = matched1[i].pt.y;

    col = homography * col;
    col /= col.at<double>(2);
    double dist = sqrt(pow(col.at<double>(0) - matched2[i].pt.x, 2) +
        pow(col.at<double>(1) - matched2[i].pt.y, 2));

    if (dist < inlier_threshold) {
        int new_i = static_cast<int>(inliers1.size());
        inliers1.push_back(matched1[i]);
        inliers2.push_back(matched2[i]);
        good_matches.push_back(DMatch(new_i, new_i, 0));
    }
}

Mat res;
drawMatches(img1, inliers1, img2, inliers2, good_matches, res);
imwrite("latch_res.png", res);

我认为这是一种比率测试,但我不明白inliershomography

的重点

0 个答案:

没有答案