void myMatch2CvMatch(const Matching& myMatch , DMatchVec& cvMatch) { int numMatch = myMatch.num; cvMatch.clear(); cvMatch.reserve(numMatch * 2); for (int i = 0; i < numMatch; i++) { cvMatch.push_back(cv::DMatch(myMatch[i].idx1, myMatch[i].idx2, myMatch[i].dist)); } }
// Extract the inliers keypoints given a mask void RobustMatcher::extractInliers(const cv::Mat &inliers_mask, const KeyPointVec &kpts1, const KeyPointVec &kpts2, KeyPointVec &kpts1_inliers, KeyPointVec &kpts2_inliers, DMatchVec &inliers_matches) { for(unsigned i = 0; i < kpts1.size(); i++) { if(inliers_mask.at<uchar>(i)) { int new_i = static_cast<int>(kpts1_inliers.size()); kpts1_inliers.push_back(kpts1[i]); kpts2_inliers.push_back(kpts2[i]); inliers_matches.push_back(cv::DMatch(new_i, new_i, 0)); } } }
// Remove matches for which NN ratio is > than threshold // return the number of removed points int RobustMatcher::ratioTest(const DMatchVec2 &matches, DMatchVec &good_matches, const KeyPointVec &kpts1, KeyPointVec &kpts1_out, const KeyPointVec &kpts2, KeyPointVec &kpts2_out) { for(size_t i = 0; i < matches.size(); i++) { cv::DMatch first = matches[i][0]; float dist1 = matches[i][0].distance; float dist2 = matches[i][1].distance; if(dist1 < nn_match_ratio_ * dist2) { kpts1_out.push_back(kpts1[first.queryIdx]); kpts2_out.push_back(kpts2[first.trainIdx]); good_matches.push_back(first); } } return static_cast<int>(good_matches.size()); }