10 #ifndef mrpt_vision_descriptor_pairing_H 11 #define mrpt_vision_descriptor_pairing_H 48 template <
class DESCRIPTOR_KDTREE>
50 std::vector<std::vector<size_t>>* pairings_1_to_multi_2,
51 std::vector<std::pair<size_t, size_t>>* pairings_1_to_2,
52 const CFeatureList& feats_img1,
const DESCRIPTOR_KDTREE& feats_img2_kdtree,
54 const size_t max_neighbors = 4,
const double max_relative_distance = 1.2,
55 const typename DESCRIPTOR_KDTREE::kdtree_t::DistanceType max_distance =
57 typename DESCRIPTOR_KDTREE::kdtree_t::DistanceType>::max())
61 ASSERT_(pairings_1_to_multi_2 !=
nullptr || pairings_1_to_2 !=
nullptr);
64 using KDTreeElementType =
typename DESCRIPTOR_KDTREE::kdtree_t::ElementType;
65 using KDTreeDistanceType =
66 typename DESCRIPTOR_KDTREE::kdtree_t::DistanceType;
68 const size_t N = feats_img1.
size();
69 if (pairings_1_to_multi_2)
70 pairings_1_to_multi_2->assign(
71 N, std::vector<size_t>());
74 pairings_1_to_2->clear();
75 pairings_1_to_2->reserve(N);
78 size_t overall_pairs = 0;
80 if (!N)
return overall_pairs;
85 feats_img1[0]->descriptors.hasDescriptorSIFT(),
86 "Request to match SIFT features but feats_img1 has no SIFT " 89 sizeof(KDTreeElementType) ==
90 sizeof(feats_img1[0]->descriptors.SIFT[0]),
91 "Incorrect data type kd_tree::ElementType for SIFT (should be " 97 feats_img1[0]->descriptors.hasDescriptorSURF(),
98 "Request to match SURF features but feats_img1 has no SURF " 101 sizeof(KDTreeElementType) ==
102 sizeof(feats_img1[0]->descriptors.SURF[0]),
103 "Incorrect data type kd_tree::ElementType for SURF (should be " 109 "This function only supports SIFT or SURFT descriptors");
112 std::vector<size_t>
indices(max_neighbors);
113 std::vector<double> distances(max_neighbors);
115 for (
size_t i = 0; i < N; i++)
119 const void* ptr_query;
121 ptr_query = &descs.
SIFT[0];
123 ptr_query = &descs.
SURF[0];
125 feats_img2_kdtree.get_kdtree().knnSearch(
126 static_cast<const KDTreeElementType*>(ptr_query),
133 const KDTreeDistanceType this_thresh =
134 std::min(max_relative_distance * distances[0], max_distance);
135 for (
size_t j = 0; j < max_neighbors; j++)
137 if (distances[j] <= this_thresh)
140 if (pairings_1_to_multi_2)
141 (*pairings_1_to_multi_2)[i].push_back(
indices[j]);
143 pairings_1_to_2->push_back(std::make_pair(i,
indices[j]));
149 return overall_pairs;
#define THROW_EXCEPTION(msg)
GLuint GLuint GLsizei GLenum const GLvoid * indices
std::vector< float > SURF
SURF feature descriptor.
#define ASSERT_(f)
Defines an assertion mechanism.
std::vector< uint8_t > SIFT
SIFT feature descriptor.
All the possible descriptors this feature may have.
Classes for computer vision, detectors, features, etc.
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
#define ASSERT_ABOVEEQ_(__A, __B)
A list of visual features, to be used as output by detectors, as input/output by trackers, etc.
TDescriptorType
The bitwise OR combination of values of TDescriptorType are used in CFeatureExtraction::computeDescri...
size_t find_descriptor_pairings(std::vector< std::vector< size_t >> *pairings_1_to_multi_2, std::vector< std::pair< size_t, size_t >> *pairings_1_to_2, const CFeatureList &feats_img1, const DESCRIPTOR_KDTREE &feats_img2_kdtree, const mrpt::vision::TDescriptorType descriptor=descSIFT, const size_t max_neighbors=4, const double max_relative_distance=1.2, const typename DESCRIPTOR_KDTREE::kdtree_t::DistanceType max_distance=std::numeric_limits< typename DESCRIPTOR_KDTREE::kdtree_t::DistanceType >::max())
Search for pairings between two sets of visual descriptors (for now, only SURF and SIFT features are ...