OpenCv:功能匹配,匹配描述符来过滤关键点?

时间:2017-07-08 16:01:35

标签: opencv computer-vision feature-extraction feature-detection

我有以下代码,用于检测和匹配在两个图像中检测到的关键点。 我检测到关键点,并将描述符存储在以下内容中:

cv::Mat descCurrent;
cv::Mat descCurrentR;

然后将它们传递给这个函数:

std::vector<DMatch> PointMatching::matchPointsOG2(cv::Mat descriptors1Cpu, cv::Mat descriptors2Cpu)
{

    descriptors1GPU.upload(descriptors1Cpu);
    descriptors2GPU.upload(descriptors2Cpu);


    // matching descriptors
    Ptr<cv::cuda::DescriptorMatcher> matcher = cv::cuda::DescriptorMatcher::createBFMatcher(NORM_HAMMING);
    vector<cv::DMatch> matches;
    vector< vector< DMatch> > knn_matches;

    matcher->knnMatch(descriptors1GPU, descriptors2GPU, knn_matches, 2);

    //Filter the matches using the ratio test
    for (std::vector<std::vector<cv::DMatch> >::const_iterator it = knn_matches.begin(); it != knn_matches.end(); ++it) {
        if (it->size() > 1 && (*it)[0].distance / (*it)[1].distance < 0.8) {
            matches.push_back((*it)[0]);
        }
    }


    return matches;

}

然后,一旦我有比赛,我这样做:

std::vector<cv::KeyPoint> keyPntsGoodL;
    std::vector<cv::KeyPoint> keyPntsGoodR;
for (size_t i = 0; i < matchR.size(); i++)
            {
                keyPntsGoodL.push_back(keyPntsCurrent[matchR[i].queryIdx]);
                keyPntsGoodR.push_back(keyPntsCurrentR[matchR[i].trainIdx]);

            }

这一切都按预期工作,我有匹配和过滤的关键点。 我的问题是:

如何以相同的方式过滤描述符? 如果我现在只想获得与keyPntsGoodL匹配的初始描述符(descCurrent)的子集,我该怎么做?

谢谢。

0 个答案:

没有答案