Main MRPT website > C++ reference for MRPT 1.9.9
multiDesc_utils.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #ifndef mrpt_multiDesc_utils_H
11 #define mrpt_multiDesc_utils_H
12 
13 #include <mrpt/vision/CFeature.h>
14 #include <mrpt/img/CImage.h>
15 #include <mrpt/math/utils.h>
18 #include <mrpt/poses/CPose3D.h>
21 
22 #include <mrpt/vision/types.h>
24 
25 namespace mrpt
26 {
27 namespace vision
28 {
29 /** \addtogroup multidesc_desc Multiresolution SIFTs (experimental)
30  * \ingroup mrpt_vision_grp
31  * @{ */
32 
33 // A 3D quantization table for storing pairs of TFeatureIDs and scales
34 using TQuantizationTable = std::map<
35  int,
36  std::map<int, std::map<int, std::deque<std::pair<TFeatureID, double>>>>>;
37 
38 void saveQTableToFile(
39  const TQuantizationTable& qTable, const std::string& filename);
40 
41 void insertHashCoeffs(const CFeature::Ptr& feat, TQuantizationTable& qTable);
42 
44  const mrpt::img::CImage& image, CFeatureList& baseList,
45  CFeatureList& currentList, TQuantizationTable& qTable,
46  const TMultiResDescOptions& desc_opts,
47  const TMultiResDescMatchOptions& match_opts);
48 
49 void updateBaseList(
50  CFeatureList& baseList, const CFeatureList& currentList,
51  const std::vector<int>& idx);
52 
54  CMatchedFeatureList& baseList, const CFeatureList& currentList,
55  const mrpt::img::CImage& currentImage,
56  const TMultiResMatchingOutput& output,
57  const TMultiResDescOptions& computeOpts,
58  const TMultiResDescMatchOptions& matchOpts);
59 
60 /** Computes the gradient of certain pixel within the image.
61  * \param image [IN] The input image.
62  * \param x [IN] The 'x' coordinate of the image point.
63  * \param y [IN] The 'y' coordinate of the image point.
64  * \param mag [OUT] The magnitude of the gradient.
65  * \param ori [OUT] The orientation of the gradient.
66  * \return True if the gradient could be computed and False if the pixel is
67  * located outside the image or at its border (where the gradient cannot be
68  * computed)
69  */
70 bool computeGradient(
71  const mrpt::img::CImage& image, const unsigned int x, const unsigned int y,
72  double& mag, double& ori);
73 
74 /** Computes the main orientations (within 80% of the peak value of orientation
75  * histogram) of a certain point within an image (for using in SIFT-based
76  * algorithms)
77  * \param image [IN] The input image.
78  * \param x [IN] The 'x' coordinate of the image point.
79  * \param y [IN] The 'y' coordinate of the image point.
80  * \param patchSize [IN] The size of the patch to be considered for
81  * computing the orientation histogram.
82  * \param orientations [OUT] A vector containing the main orientations of
83  * the image point.
84  * \param sigma [IN] The sigma value of the Gaussian kernel used to
85  * smooth the orientation histogram (typically 7.5 px).
86  */
88  const mrpt::img::CImage& image, const unsigned int x, const unsigned int y,
89  const unsigned int patchSize, std::vector<double>& orientations,
90  const double& sigma);
91 
92 /** Inserts the orientation value of a certain pixel within the keypoint
93  * neighbourhood into the histogram of orientations. This value can
94  * affect to more than one entry within the histogram.
95  * \param hist [IN/OUT] The histogram of orientations.
96  * \param cbin [IN] The entry rotated column bin.
97  * \param rbin [IN] The entry rotated row bin.
98  * \param obin [IN] The entry rotated orientation bin.
99  * \param mag [IN] The gradient magnitude value in the pixel.
100  * \param d [IN] The number of row (and column) bins used in the
101  * histogram (typically 4).
102  * \param n [IN] The number of orienation bins used in the
103  * histogram (typically 8).
104  */
106  std::vector<double>& hist, const double& cbin, const double& rbin,
107  const double& obin, const double& mag, const int d, const int n);
108 
109 /** Computes the SIFT-like descriptor of a certain point within an image at the
110  * base scale, i.e. its rotated orientation histogram.
111  * \param image [IN] The input image.
112  * \param x [IN] The 'x' coordinate of the image point.
113  * \param y [IN] The 'y' coordinate of the image point.
114  * \param patchSize [IN] The size of the patch to be considered for
115  * computing the orientation histogram.
116  * \param orientation [IN] The orientation considered for this point
117  * (used to rotate the patch).
118  * \param orientation [OUT] The computed SIFT-like descriptor.
119  * \param opts [IN] The options for computing the SIFT-like
120  * descriptor.
121  * \param hashCoeffs [OUT] A vector containing the computed coefficients
122  * for the HASH table used in relocalization.
123  * \sa TMultiResDescOptions
124  */
126  const mrpt::img::CImage& image, const unsigned int x, const unsigned int y,
127  const unsigned int patchSize, const double& orientation,
128  std::vector<int32_t>& descriptor, const TMultiResDescOptions& opts,
129  std::vector<int32_t>& hashCoeffs);
130 
131 /** Matches two CFeatureList containing mulit-resolution descriptors. The first
132  * list is taken as a base, i.e. its features must contain multi-resolution
133  * descriptors
134  * at a set of different scales. The second list doesn't need to contain such
135  * information because it will be computed if necessary according to the
136  * the fulfillment of some restriction regarding the matching process. This
137  * function will try to find the best matches within list2 corresponding to the
138  * features
139  * within base list list1.
140  * \param list1 [IN] The base list of features.
141  * \param list2 [IN/OUT] The other list of features.
142  * \param rightImage [IN] The image from where the list2 was
143  * extracted. It's used to compute the descriptor of these features if
144  * necessary.
145  * \param output [OUT] The output structure with the matching
146  * information.
147  * \param matchOpts [IN] The options structure for the matching
148  * process.
149  * \param computeOpts [IN] The options structure for the
150  * descriptor computation process.
151  * \return A structure containing the results of the matching.
152  * \sa TMultiResDescMatchOptions, TMultiResDescOptions,
153  * TMultiResMatchingOutput
154  */
156  const CFeatureList& list1, CFeatureList& list2,
157  const mrpt::img::CImage& rightImage,
158  const TMultiResDescMatchOptions& matchOpts,
159  const TMultiResDescOptions& computeOpts);
160 
161 /** Matches two CMatchedFeatureList containing mulit-resolution descriptors.
162  * This is performed for both the "left" and "right" lists
163  * The first matched list is taken as a base, i.e. its features must contain
164  * multi-resolution descriptors
165  * at a set of different scales. The second list doesn't need to contain such
166  * information because it will be computed if necessary according to the
167  * the fulfillment of some restriction regarding the matching process. This
168  * function will try to find the best matches within list2 corresponding to the
169  * features
170  * \param mList1 [IN] The base list.
171  * \param mList2 [IN] The other list of features.
172  * \param leftImage [IN] The image from where the list2 was
173  * extracted. It's used to compute the descriptor of these features if
174  * necessary.
175  * \param rightImage [IN] The image from where the list2 was
176  * extracted. It's used to compute the descriptor of these features if
177  * necessary.
178  * \param matchOpts [IN] The options structure for the matching
179  * process.
180  * \param computeOpts [IN] The options structure for the
181  * descriptor computation process.
182  * \return The number of matches found
183  * \sa TMultiResDescMatchOptions
184  */
186  CMatchedFeatureList& mList1, CMatchedFeatureList& mList2,
187  const mrpt::img::CImage& leftImage, const mrpt::img::CImage& rightImage,
188  const TMultiResDescMatchOptions& matchOpts,
189  const TMultiResDescOptions& computeOpts);
190 
191 /** Computes more multi-resolution SIFT-like descriptors for a feature using its
192  * position in a new image. This
193  * is called when we have found a match between a feature and itself in a new
194  * frame but it has been found in
195  * a boundary scale. We now expand the range of scales, orientations and
196  * descriptors for that feature.
197  * \param image [IN] The new frame.
198  * \param inputFeat [IN] The feature in the new frame.
199  * \param outputFeat [OUT] The base feature (detected in the base frame).
200  * \param lowerScales [IN] If we should find descriptors for lower scales
201  * or for higher ones.
202  * \param opts [IN] The options for computing the new descriptors.
203  */
205  const mrpt::img::CImage& image, const CFeature::Ptr& inputFeat,
206  CFeature::Ptr& outputFeat, const bool& lowerScales,
207  const TMultiResDescOptions& opts);
208 
209 /** Computes the initial and final scales where to look when finding a match
210  * between multi-resolution features.
211  * Both features must have their "depth" member properly computed.
212  * \param feat1 [IN] The base feature which MUST contain a set of
213  * different scales.
214  * \param feat2 [IN] The other feature which must be computed at
215  * base scale (1.0).
216  * \param firstScale [OUT] The initial scale (within [0
217  * feat1->multiScale.size()-1]) where to look.
218  * \param firstScale [OUT] The final scale (within [0
219  * feat1->multiScale.size()-1]) where to look.
220  */
221 void setProperScales(
222  const CFeature::Ptr& feat1, const CFeature::Ptr& feat2, int& firstScale,
223  int& lastScale);
224 
225 /** Computes the multi-resolution SIFT-like descriptor of a set of matched
226  * features
227  * \param imageLeft [IN] The input left image.
228  * \param imageRight [IN] The input right image.
229  * \param matchedFeats [IN/OUT] The list of matched features. They will be
230  * updated with the multi-scales, multi-orientations, multi-descriptors and
231  * depth information.
232  * \param opts [IN] The options structure for the descriptor
233  * computation process.
234  * \sa TMultiResDescOptions
235  */
237  const mrpt::img::CImage& imageLeft, const mrpt::img::CImage& imageRight,
238  CMatchedFeatureList& matchedFeats, const TMultiResDescOptions& opts);
239 
240 /** Computes the multi-resolution SIFT-like descriptor of a features
241  * \param image [IN] The input left image.
242  * \param feat [IN/OUT] The feature. It will be updated with the
243  * multi-scales, multi-orientations, multi-descriptors
244  * \param opts [IN] The options structure for the descriptor
245  * computation process.
246  * \sa TMultiResDescOptions
247  */
249  const mrpt::img::CImage& image, CFeature::Ptr& feat,
250  const TMultiResDescOptions& opts);
251 
252 /** Computes the multi-resolution SIFT-like descriptor of a list of features
253  * \param image [IN] The input image.
254  * \param list [IN/OUT] The list of features. They will be updated
255  * with the multi-scales, multi-orientations and multi-descriptors information.
256  * \param opts [IN] The options structure for the descriptor
257  * computation process.
258  * \sa TMultiResDescOptions
259  */
260 std::vector<bool> computeMultiResolutionDescriptors(
261  const mrpt::img::CImage& image, CFeatureList& list,
262  const TMultiResDescOptions& opts);
263 
264 /** Computes the multi-resolution SIFT-like descriptor of a list of features
265  * \param image [IN] The input image.
266  * \param list [IN/OUT] The list of features. They will be updated
267  * with the multi-scales, multi-orientations and multi-descriptors information.
268  * \param opts [IN] The options structure for the descriptor
269  * computation process.
270  * \sa TMultiResDescOptions
271  */
273  const mrpt::img::CImage& image, CFeatureList& list,
274  const TMultiResDescOptions& opts);
275 
276 /** @} */ // end of grouping
277 } // namespace vision
278 } // namespace mrpt
279 
280 #endif
n
GLenum GLsizei n
Definition: glext.h:5074
mrpt::vision::computeMultiOrientations
void computeMultiOrientations(const mrpt::img::CImage &image, CFeatureList &list, const TMultiResDescOptions &opts)
Computes the multi-resolution SIFT-like descriptor of a list of features.
Definition: multiDesc_utils.cpp:2262
mrpt::vision::interpolateHistEntry
void interpolateHistEntry(std::vector< double > &hist, const double &cbin, const double &rbin, const double &obin, const double &mag, const int d, const int n)
Inserts the orientation value of a certain pixel within the keypoint neighbourhood into the histogram...
Definition: multiDesc_utils.cpp:716
mrpt::vision::TMultiResMatchingOutput
Struct containing the output after matching multi-resolution SIFT-like descriptors.
Definition: vision/include/mrpt/vision/types.h:519
mrpt::vision::relocalizeMultiDesc
TMultiResMatchingOutput relocalizeMultiDesc(const mrpt::img::CImage &image, CFeatureList &baseList, CFeatureList &currentList, TQuantizationTable &qTable, const TMultiResDescOptions &desc_opts, const TMultiResDescMatchOptions &match_opts)
Definition: multiDesc_utils.cpp:129
CObservationVisualLandmarks.h
mrpt::vision::TMultiResDescOptions
Struct containing the options when computing the multi-resolution SIFT-like descriptors.
Definition: vision/include/mrpt/vision/types.h:644
mrpt::vision::TMultiResDescMatchOptions
Struct containing the options when matching multi-resolution SIFT-like descriptors.
Definition: vision/include/mrpt/vision/types.h:549
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::vision::computeGradient
bool computeGradient(const mrpt::img::CImage &image, const unsigned int x, const unsigned int y, double &mag, double &ori)
Computes the gradient of certain pixel within the image.
Definition: multiDesc_utils.cpp:558
chessboard_camera_calib.h
mrpt::vision::CFeatureList
A list of visual features, to be used as output by detectors, as input/output by trackers,...
Definition: CFeature.h:304
mrpt::vision::computeHistogramOfOrientations
void computeHistogramOfOrientations(const mrpt::img::CImage &image, const unsigned int x, const unsigned int y, const unsigned int patchSize, const double &orientation, std::vector< int32_t > &descriptor, const TMultiResDescOptions &opts, std::vector< int32_t > &hashCoeffs)
Computes the SIFT-like descriptor of a certain point within an image at the base scale,...
Definition: multiDesc_utils.cpp:819
mrpt::vision::CMatchedFeatureList
A list of features.
Definition: CFeature.h:503
CLandmarksMap.h
mrpt::vision::CFeature::Ptr
std::shared_ptr< CFeature > Ptr
Definition: CFeature.h:60
mrpt::vision::setProperScales
void setProperScales(const CFeature::Ptr &feat1, const CFeature::Ptr &feat2, int &firstScale, int &lastScale)
Computes the initial and final scales where to look when finding a match between multi-resolution fea...
Definition: multiDesc_utils.cpp:1831
TMatchingPair.h
mrpt::vision::updateBaseList
void updateBaseList(CFeatureList &baseList, const CFeatureList &currentList, const std::vector< int > &idx)
Definition: multiDesc_utils.cpp:409
mrpt::vision::computeMultiResolutionDescriptors
void computeMultiResolutionDescriptors(const mrpt::img::CImage &imageLeft, const mrpt::img::CImage &imageRight, CMatchedFeatureList &matchedFeats, const TMultiResDescOptions &opts)
Computes the multi-resolution SIFT-like descriptor of a set of matched features.
Definition: multiDesc_utils.cpp:1896
mrpt::vision::saveQTableToFile
void saveQTableToFile(const TQuantizationTable &qTable, const std::string &filename)
Definition: multiDesc_utils.cpp:97
mrpt::vision::TQuantizationTable
std::map< int, std::map< int, std::map< int, std::deque< std::pair< TFeatureID, double > >> >> TQuantizationTable
Definition: multiDesc_utils.h:36
utils.h
mrpt::img::CImage
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130
CPose3D.h
mrpt::vision::computeMoreDescriptors
int computeMoreDescriptors(const mrpt::img::CImage &image, const CFeature::Ptr &inputFeat, CFeature::Ptr &outputFeat, const bool &lowerScales, const TMultiResDescOptions &opts)
Computes more multi-resolution SIFT-like descriptors for a feature using its position in a new image.
Definition: multiDesc_utils.cpp:1628
CLoadableOptions.h
image
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glext.h:3552
mrpt::vision::matchMultiResolutionFeatures
TMultiResMatchingOutput matchMultiResolutionFeatures(const CFeatureList &list1, CFeatureList &list2, const mrpt::img::CImage &rightImage, const TMultiResDescMatchOptions &matchOpts, const TMultiResDescOptions &computeOpts)
Matches two CFeatureList containing mulit-resolution descriptors.
Definition: multiDesc_utils.cpp:1020
mrpt::vision::insertHashCoeffs
void insertHashCoeffs(const CFeature::Ptr &feat, TQuantizationTable &qTable)
Definition: multiDesc_utils.cpp:55
string
GLsizei const GLchar ** string
Definition: glext.h:4101
CImage.h
CFeature.h
types.h
y
GLenum GLint GLint y
Definition: glext.h:3538
x
GLenum GLint x
Definition: glext.h:3538
mrpt::vision::checkScalesAndFindMore
void checkScalesAndFindMore(CMatchedFeatureList &baseList, const CFeatureList &currentList, const mrpt::img::CImage &currentImage, const TMultiResMatchingOutput &output, const TMultiResDescOptions &computeOpts, const TMultiResDescMatchOptions &matchOpts)
Definition: multiDesc_utils.cpp:469
mrpt::vision::computeMainOrientations
bool computeMainOrientations(const mrpt::img::CImage &image, const unsigned int x, const unsigned int y, const unsigned int patchSize, std::vector< double > &orientations, const double &sigma)
Computes the main orientations (within 80% of the peak value of orientation histogram) of a certain p...
Definition: multiDesc_utils.cpp:598



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST