10 #ifndef mrpt_vision_descriptor_pairing_H
11 #define mrpt_vision_descriptor_pairing_H
52 template <
class DESCRIPTOR_KDTREE>
54 std::vector<vector_size_t> * pairings_1_to_multi_2,
55 std::vector<std::pair<size_t,size_t> > * pairings_1_to_2,
57 const DESCRIPTOR_KDTREE & feats_img2_kdtree,
59 const size_t max_neighbors = 4,
60 const double max_relative_distance = 1.2,
61 const typename DESCRIPTOR_KDTREE::kdtree_t::DistanceType max_distance = std::numeric_limits<typename DESCRIPTOR_KDTREE::kdtree_t::DistanceType>::max()
66 ASSERT_(pairings_1_to_multi_2!=NULL || pairings_1_to_2!=NULL)
68 typedef typename DESCRIPTOR_KDTREE::kdtree_t::ElementType KDTreeElementType;
69 typedef typename DESCRIPTOR_KDTREE::kdtree_t::DistanceType KDTreeDistanceType;
71 const size_t N=feats_img1.
size();
72 if (pairings_1_to_multi_2) pairings_1_to_multi_2->assign(N,
vector_size_t());
73 if (pairings_1_to_2) { pairings_1_to_2->clear(); pairings_1_to_2->reserve(N); }
75 size_t overall_pairs = 0;
77 if (!N)
return overall_pairs;
80 ASSERTMSG_(feats_img1[0]->descriptors.hasDescriptorSIFT(),
"Request to match SIFT features but feats_img1 has no SIFT descriptors!")
81 ASSERTMSG_(
sizeof(KDTreeElementType)==
sizeof(feats_img1[0]->descriptors.SIFT[0]),
"Incorrect data type kd_tree::ElementType for SIFT (should be uint8_t)")
84 ASSERTMSG_(feats_img1[0]->descriptors.hasDescriptorSURF(),
"Request to match SURF features but feats_img1 has no SURF descriptors!")
85 ASSERTMSG_(
sizeof(KDTreeElementType)==
sizeof(feats_img1[0]->descriptors.SURF[0]),
"Incorrect data type kd_tree::ElementType for SURF (should be float)")
87 else {
THROW_EXCEPTION(
"This function only supports SIFT or SURFT descriptors") }
89 std::vector<size_t> indices(max_neighbors);
90 std::vector<double> distances(max_neighbors);
92 for (
size_t i=0;i<N;i++)
96 const void * ptr_query;
98 else if (descriptor==
descSURF) ptr_query = &descs.
SURF[0];
100 feats_img2_kdtree.get_kdtree().knnSearch(
101 static_cast<const KDTreeElementType*>( ptr_query ),
103 &indices[0], &distances[0]
107 const KDTreeDistanceType this_thresh = std::min( max_relative_distance*distances[0], max_distance);
108 for (
size_t j=0;j<max_neighbors;j++)
110 if (distances[j]<=this_thresh) {
112 if (pairings_1_to_multi_2) (*pairings_1_to_multi_2)[i].push_back(indices[j]);
113 if (pairings_1_to_2) pairings_1_to_2->push_back(std::make_pair(i,indices[j]));
118 return overall_pairs;
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 ...
#define THROW_EXCEPTION(msg)
std::vector< float > SURF
SURF feature descriptor.
std::vector< size_t > vector_size_t
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)
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
#define ASSERTMSG_(f, __ERROR_MSG)
Structure to hold the parameters of a pinhole camera model.