0

I have the following code, which I use to detect and match Keypoints detected in two images. I detect the keypoints, and store the descriptors in these:

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

Then pass them to this function:

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;

}

Then, once I have the matches, I do this:

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]);

            }

This is all working as expected, I have the keypoints that have been matched and filtered. My question is:

How can I filter the descriptors in the same way? If I now want to get only the subset of the initial descriptors (descCurrent) that match keyPntsGoodL, how can I do this?

Thank you.

anti
  • 3,011
  • 7
  • 36
  • 86
  • the matching works on descriptors, not keypoints... so you should already have your "good" descriptors. – swiss_knight Jul 09 '17 at 10:37
  • Hi, thanks for your reply. I have the descriptors that match the initial found keypoints. What I need is the subset that correspond to the filtered keypoints that are returned from the matching function. – anti Jul 09 '17 at 11:32
  • actually I use it with Python, but the idea should be the same: a `matches` object created with some matching function over descriptors already contains the keypoints that have matched: http://docs.opencv.org/trunk/dc/dc3/tutorial_py_matcher.html if this can help? I can't do very much. – swiss_knight Jul 09 '17 at 12:28
  • @anti did you ever figure this out? – dmarnel Aug 17 '19 at 12:10

0 Answers0