MCPcopy Create free account
hub / github.com/colmap/colmap / FindBestMatchesOneWayIndex

Function FindBestMatchesOneWayIndex

src/colmap/feature/sift.cc:864–911  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

862}
863
864size_t FindBestMatchesOneWayIndex(const Eigen::RowMajorMatrixXi& indices,
865 const Eigen::RowMajorMatrixXf& l2_dists,
866 const float max_ratio,
867 const float max_distance,
868 std::vector<int>* matches) {
869 const float max_l2_dist = kSqSiftDescriptorNorm * max_distance * max_distance;
870
871 size_t num_matches = 0;
872 matches->resize(indices.rows(), -1);
873
874 for (int d1_idx = 0; d1_idx < indices.rows(); ++d1_idx) {
875 int best_d2_idx = -1;
876 float best_l2_dist = std::numeric_limits<float>::max();
877 float second_best_l2_dist = std::numeric_limits<float>::max();
878 for (int n_idx = 0; n_idx < indices.cols(); ++n_idx) {
879 const int d2_idx = indices(d1_idx, n_idx);
880 const float l2_dist = l2_dists(d1_idx, n_idx);
881 if (l2_dist < best_l2_dist) {
882 best_d2_idx = d2_idx;
883 second_best_l2_dist = best_l2_dist;
884 best_l2_dist = l2_dist;
885 } else if (l2_dist < second_best_l2_dist) {
886 second_best_l2_dist = l2_dist;
887 }
888 }
889
890 // Check if any match found.
891 if (best_d2_idx == -1) {
892 continue;
893 }
894
895 // Check if match distance passes threshold.
896 if (best_l2_dist > max_l2_dist) {
897 continue;
898 }
899
900 // Check if match passes ratio test. Keep this comparison >= in order to
901 // ensure that the case of best == second_best is detected.
902 if (std::sqrt(best_l2_dist) >= max_ratio * std::sqrt(second_best_l2_dist)) {
903 continue;
904 }
905
906 ++num_matches;
907 (*matches)[d1_idx] = best_d2_idx;
908 }
909
910 return num_matches;
911}
912
913void FindBestMatchesIndex(const Eigen::RowMajorMatrixXi& indices_1to2,
914 const Eigen::RowMajorMatrixXf& l2_dists_1to2,

Callers 1

FindBestMatchesIndexFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected