10 #ifndef mrpt_vision_descriptor_pairing_H 11 #define mrpt_vision_descriptor_pairing_H 50 template <
class DESCRIPTOR_KDTREE>
52 std::vector<vector_size_t>* pairings_1_to_multi_2,
53 std::vector<std::pair<size_t, size_t>>* pairings_1_to_2,
54 const CFeatureList& feats_img1,
const DESCRIPTOR_KDTREE& feats_img2_kdtree,
56 const size_t max_neighbors = 4,
const double max_relative_distance = 1.2,
57 const typename DESCRIPTOR_KDTREE::kdtree_t::DistanceType max_distance =
59 typename DESCRIPTOR_KDTREE::kdtree_t::DistanceType>::max())
63 ASSERT_(pairings_1_to_multi_2 !=
nullptr || pairings_1_to_2 !=
nullptr)
65 typedef typename DESCRIPTOR_KDTREE::kdtree_t::ElementType
69 typename DESCRIPTOR_KDTREE::kdtree_t::DistanceType KDTreeDistanceType;
71 const size_t N = feats_img1.
size();
72 if (pairings_1_to_multi_2)
73 pairings_1_to_multi_2->assign(
77 pairings_1_to_2->clear();
78 pairings_1_to_2->reserve(N);
81 size_t overall_pairs = 0;
83 if (!N)
return overall_pairs;
88 feats_img1[0]->descriptors.hasDescriptorSIFT(),
89 "Request to match SIFT features but feats_img1 has no SIFT " 92 sizeof(KDTreeElementType) ==
93 sizeof(feats_img1[0]->descriptors.SIFT[0]),
94 "Incorrect data type kd_tree::ElementType for SIFT (should be " 100 feats_img1[0]->descriptors.hasDescriptorSURF(),
101 "Request to match SURF features but feats_img1 has no SURF " 104 sizeof(KDTreeElementType) ==
105 sizeof(feats_img1[0]->descriptors.SURF[0]),
106 "Incorrect data type kd_tree::ElementType for SURF (should be " 111 THROW_EXCEPTION(
"This function only supports SIFT or SURFT descriptors")
114 std::vector<size_t>
indices(max_neighbors);
115 std::vector<double> distances(max_neighbors);
117 for (
size_t i = 0; i < N; i++)
121 const void* ptr_query;
123 ptr_query = &descs.
SIFT[0];
125 ptr_query = &descs.
SURF[0];
127 feats_img2_kdtree.get_kdtree().knnSearch(
128 static_cast<const KDTreeElementType*>(ptr_query),
135 const KDTreeDistanceType this_thresh =
136 std::min(max_relative_distance * distances[0], max_distance);
137 for (
size_t j = 0; j < max_neighbors; j++)
139 if (distances[j] <= this_thresh)
142 if (pairings_1_to_multi_2)
143 (*pairings_1_to_multi_2)[i].push_back(
indices[j]);
145 pairings_1_to_2->push_back(std::make_pair(i,
indices[j]));
151 return overall_pairs;
#define THROW_EXCEPTION(msg)
GLuint GLuint GLsizei GLenum const GLvoid * indices
std::vector< float > SURF
SURF feature descriptor.
std::vector< uint8_t > SIFT
SIFT feature descriptor.
All the possible descriptors this feature may have.
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...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define ASSERT_ABOVEEQ_(__A, __B)
size_t find_descriptor_pairings(std::vector< 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 ...
std::vector< size_t > vector_size_t
#define ASSERTMSG_(f, __ERROR_MSG)