Exemplo n.º 1
0
void crossCheckMatching( cv::Ptr<DescriptorMatcher>& descriptorMatcher,
                         const Mat& descriptors1, const Mat& descriptors2,
                         vector<DMatch>& filteredMatches12, int knn )
{
    filteredMatches12.clear();
    vector<vector<DMatch> > matches12, matches21;
    descriptorMatcher->knnMatch( descriptors1, descriptors2, matches12, knn );
    descriptorMatcher->knnMatch( descriptors2, descriptors1, matches21, knn );
    for( size_t m = 0; m < matches12.size(); m++ )
    {
        bool findCrossCheck = false;
        for( size_t fk = 0; fk < matches12[m].size(); fk++ )
        {
            DMatch forward = matches12[m][fk];

            for( size_t bk = 0; bk < matches21[forward.trainIdx].size(); bk++ )
            {
                DMatch backward = matches21[forward.trainIdx][bk];
                if( backward.trainIdx == forward.queryIdx )
                {
                    filteredMatches12.push_back(forward);
                    findCrossCheck = true;
                    break;
                }
            }
            if( findCrossCheck ) break;
        }
    }
}
 void crossCheckMatching(
         const cv::Mat& descriptors_0, const cv::Mat& descriptors_1,
         std::vector<cv::DMatch>& matches, int knn = 1)
 {
     matches.clear();
     std::vector<std::vector<cv::DMatch> > matches12, matches21;
     matcher_->knnMatch(descriptors_0, descriptors_1, matches12, knn);
     matcher_->knnMatch(descriptors_1, descriptors_0, matches21, knn);
     for (size_t m = 0; m < matches12.size(); ++m)
     {
         bool findCrossCheck = false;
         for(size_t fk = 0; fk < matches12[m].size(); ++fk)
         {
             cv::DMatch forward = matches12[m][fk];
             for (size_t bk = 0; bk < matches21[forward.trainIdx].size(); ++bk)
             {
                 cv::DMatch backward = matches21[forward.trainIdx][bk];
                 if (backward.trainIdx == forward.queryIdx)
                 {
                     matches.push_back(forward);
                     findCrossCheck = true;
                     break;
                 }
             }
             if (findCrossCheck) break;
         }
     }
 }