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-2017, 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/utils/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 typedef std::map<
35  int,
36  std::map<int, std::map<int, std::deque<std::pair<TFeatureID, double>>>>>
38 
39 void saveQTableToFile(
40  const TQuantizationTable& qTable, const std::string& filename);
41 
42 void insertHashCoeffs(const CFeature::Ptr& feat, TQuantizationTable& qTable);
43 
45  const mrpt::utils::CImage& image, CFeatureList& baseList,
46  CFeatureList& currentList, TQuantizationTable& qTable,
47  const TMultiResDescOptions& desc_opts,
48  const TMultiResDescMatchOptions& match_opts);
49 
50 void updateBaseList(
51  CFeatureList& baseList, const CFeatureList& currentList,
52  const std::vector<int>& idx);
53 
55  CMatchedFeatureList& baseList, const CFeatureList& currentList,
56  const mrpt::utils::CImage& currentImage,
57  const TMultiResMatchingOutput& output,
58  const TMultiResDescOptions& computeOpts,
59  const TMultiResDescMatchOptions& matchOpts);
60 
61 /** Computes the gradient of certain pixel within the image.
62  * \param image [IN] The input image.
63  * \param x [IN] The 'x' coordinate of the image point.
64  * \param y [IN] The 'y' coordinate of the image point.
65  * \param mag [OUT] The magnitude of the gradient.
66  * \param ori [OUT] The orientation of the gradient.
67  * \return True if the gradient could be computed and False if the pixel is
68  * located outside the image or at its border (where the gradient cannot be
69  * computed)
70  */
71 bool computeGradient(
72  const mrpt::utils::CImage& image, const unsigned int x,
73  const unsigned int y, double& mag, double& ori);
74 
75 /** Computes the main orientations (within 80% of the peak value of orientation
76  * histogram) of a certain point within an image (for using in SIFT-based
77  * algorithms)
78  * \param image [IN] The input image.
79  * \param x [IN] The 'x' coordinate of the image point.
80  * \param y [IN] The 'y' coordinate of the image point.
81  * \param patchSize [IN] The size of the patch to be considered for
82  * computing the orientation histogram.
83  * \param orientations [OUT] A vector containing the main orientations of
84  * the image point.
85  * \param sigma [IN] The sigma value of the Gaussian kernel used to
86  * smooth the orientation histogram (typically 7.5 px).
87  */
89  const mrpt::utils::CImage& image, const unsigned int x,
90  const unsigned int y, const unsigned int patchSize,
91  std::vector<double>& orientations, const double& sigma);
92 
93 /** Inserts the orientation value of a certain pixel within the keypoint
94  * neighbourhood into the histogram of orientations. This value can
95  * affect to more than one entry within the histogram.
96  * \param hist [IN/OUT] The histogram of orientations.
97  * \param cbin [IN] The entry rotated column bin.
98  * \param rbin [IN] The entry rotated row bin.
99  * \param obin [IN] The entry rotated orientation bin.
100  * \param mag [IN] The gradient magnitude value in the pixel.
101  * \param d [IN] The number of row (and column) bins used in the
102  * histogram (typically 4).
103  * \param n [IN] The number of orienation bins used in the
104  * histogram (typically 8).
105  */
107  std::vector<double>& hist, const double& cbin, const double& rbin,
108  const double& obin, const double& mag, const int d, const int n);
109 
110 /** Computes the SIFT-like descriptor of a certain point within an image at the
111  * base scale, i.e. its rotated orientation histogram.
112  * \param image [IN] The input image.
113  * \param x [IN] The 'x' coordinate of the image point.
114  * \param y [IN] The 'y' coordinate of the image point.
115  * \param patchSize [IN] The size of the patch to be considered for
116  * computing the orientation histogram.
117  * \param orientation [IN] The orientation considered for this point
118  * (used to rotate the patch).
119  * \param orientation [OUT] The computed SIFT-like descriptor.
120  * \param opts [IN] The options for computing the SIFT-like
121  * descriptor.
122  * \param hashCoeffs [OUT] A vector containing the computed coefficients
123  * for the HASH table used in relocalization.
124  * \sa TMultiResDescOptions
125  */
127  const mrpt::utils::CImage& image, const unsigned int x,
128  const unsigned int y, const unsigned int patchSize,
129  const double& orientation, std::vector<int32_t>& descriptor,
130  const TMultiResDescOptions& opts, std::vector<int32_t>& hashCoeffs);
131 
132 /** Matches two CFeatureList containing mulit-resolution descriptors. The first
133  * list is taken as a base, i.e. its features must contain multi-resolution
134  * descriptors
135  * at a set of different scales. The second list doesn't need to contain such
136  * information because it will be computed if necessary according to the
137  * the fulfillment of some restriction regarding the matching process. This
138  * function will try to find the best matches within list2 corresponding to the
139  * features
140  * within base list list1.
141  * \param list1 [IN] The base list of features.
142  * \param list2 [IN/OUT] The other list of features.
143  * \param rightImage [IN] The image from where the list2 was
144  * extracted. It's used to compute the descriptor of these features if
145  * necessary.
146  * \param output [OUT] The output structure with the matching
147  * information.
148  * \param matchOpts [IN] The options structure for the matching
149  * process.
150  * \param computeOpts [IN] The options structure for the
151  * descriptor computation process.
152  * \return A structure containing the results of the matching.
153  * \sa TMultiResDescMatchOptions, TMultiResDescOptions,
154  * TMultiResMatchingOutput
155  */
157  const CFeatureList& list1, CFeatureList& list2,
158  const mrpt::utils::CImage& rightImage,
159  const TMultiResDescMatchOptions& matchOpts,
160  const TMultiResDescOptions& computeOpts);
161 
162 /** Matches two CMatchedFeatureList containing mulit-resolution descriptors.
163  * This is performed for both the "left" and "right" lists
164  * The first matched list is taken as a base, i.e. its features must contain
165  * multi-resolution descriptors
166  * at a set of different scales. The second list doesn't need to contain such
167  * information because it will be computed if necessary according to the
168  * the fulfillment of some restriction regarding the matching process. This
169  * function will try to find the best matches within list2 corresponding to the
170  * features
171  * \param mList1 [IN] The base list.
172  * \param mList2 [IN] The other list of features.
173  * \param leftImage [IN] The image from where the list2 was
174  * extracted. It's used to compute the descriptor of these features if
175  * necessary.
176  * \param rightImage [IN] The image from where the list2 was
177  * extracted. It's used to compute the descriptor of these features if
178  * necessary.
179  * \param matchOpts [IN] The options structure for the matching
180  * process.
181  * \param computeOpts [IN] The options structure for the
182  * descriptor computation process.
183  * \return The number of matches found
184  * \sa TMultiResDescMatchOptions
185  */
187  CMatchedFeatureList& mList1, CMatchedFeatureList& mList2,
188  const mrpt::utils::CImage& leftImage, const mrpt::utils::CImage& rightImage,
189  const TMultiResDescMatchOptions& matchOpts,
190  const TMultiResDescOptions& computeOpts);
191 
192 /** Computes more multi-resolution SIFT-like descriptors for a feature using its
193  * position in a new image. This
194  * is called when we have found a match between a feature and itself in a new
195  * frame but it has been found in
196  * a boundary scale. We now expand the range of scales, orientations and
197  * descriptors for that feature.
198  * \param image [IN] The new frame.
199  * \param inputFeat [IN] The feature in the new frame.
200  * \param outputFeat [OUT] The base feature (detected in the base frame).
201  * \param lowerScales [IN] If we should find descriptors for lower scales
202  * or for higher ones.
203  * \param opts [IN] The options for computing the new descriptors.
204  */
206  const mrpt::utils::CImage& image, const CFeature::Ptr& inputFeat,
207  CFeature::Ptr& outputFeat, const bool& lowerScales,
208  const TMultiResDescOptions& opts);
209 
210 /** Computes the initial and final scales where to look when finding a match
211  * between multi-resolution features.
212  * Both features must have their "depth" member properly computed.
213  * \param feat1 [IN] The base feature which MUST contain a set of
214  * different scales.
215  * \param feat2 [IN] The other feature which must be computed at
216  * base scale (1.0).
217  * \param firstScale [OUT] The initial scale (within [0
218  * feat1->multiScale.size()-1]) where to look.
219  * \param firstScale [OUT] The final scale (within [0
220  * feat1->multiScale.size()-1]) where to look.
221  */
222 void setProperScales(
223  const CFeature::Ptr& feat1, const CFeature::Ptr& feat2, int& firstScale,
224  int& lastScale);
225 
226 /** Computes the multi-resolution SIFT-like descriptor of a set of matched
227  * features
228  * \param imageLeft [IN] The input left image.
229  * \param imageRight [IN] The input right image.
230  * \param matchedFeats [IN/OUT] The list of matched features. They will be
231  * updated with the multi-scales, multi-orientations, multi-descriptors and
232  * depth information.
233  * \param opts [IN] The options structure for the descriptor
234  * computation process.
235  * \sa TMultiResDescOptions
236 */
238  const mrpt::utils::CImage& imageLeft, const mrpt::utils::CImage& imageRight,
239  CMatchedFeatureList& matchedFeats, const TMultiResDescOptions& opts);
240 
241 /** Computes the multi-resolution SIFT-like descriptor of a features
242  * \param image [IN] The input left image.
243  * \param feat [IN/OUT] The feature. It will be updated with the
244  * multi-scales, multi-orientations, multi-descriptors
245  * \param opts [IN] The options structure for the descriptor
246  * computation process.
247  * \sa TMultiResDescOptions
248 */
251  const TMultiResDescOptions& opts);
252 
253 /** Computes the multi-resolution SIFT-like descriptor of a list of features
254  * \param image [IN] The input image.
255  * \param list [IN/OUT] The list of features. They will be updated
256  * with the multi-scales, multi-orientations and multi-descriptors information.
257  * \param opts [IN] The options structure for the descriptor
258  * computation process.
259  * \sa TMultiResDescOptions
260  */
261 std::vector<bool> computeMultiResolutionDescriptors(
262  const mrpt::utils::CImage& image, CFeatureList& list,
263  const TMultiResDescOptions& opts);
264 
265 /** Computes the multi-resolution SIFT-like descriptor of a list of features
266  * \param image [IN] The input image.
267  * \param list [IN/OUT] The list of features. They will be updated
268  * with the multi-scales, multi-orientations and multi-descriptors information.
269  * \param opts [IN] The options structure for the descriptor
270  * computation process.
271  * \sa TMultiResDescOptions
272  */
274  const mrpt::utils::CImage& image, CFeatureList& list,
275  const TMultiResDescOptions& opts);
276 
277 /** @} */ // end of grouping
278 }
279 } // end-namespace-mrpt
280 
281 #endif
std::shared_ptr< CFeature > Ptr
Definition: CFeature.h:58
bool computeMainOrientations(const mrpt::utils::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...
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:118
void computeMultiResolutionDescriptors(const mrpt::utils::CImage &imageLeft, const mrpt::utils::CImage &imageRight, CMatchedFeatureList &matchedFeats, const TMultiResDescOptions &opts)
Computes the multi-resolution SIFT-like descriptor of a set of matched features.
GLenum GLsizei n
Definition: glext.h:5074
Struct containing the output after matching multi-resolution SIFT-like descriptors.
bool computeGradient(const mrpt::utils::CImage &image, const unsigned int x, const unsigned int y, double &mag, double &ori)
Computes the gradient of certain pixel within the image.
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...
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glext.h:3551
void computeHistogramOfOrientations(const mrpt::utils::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, i.e.
int computeMoreDescriptors(const mrpt::utils::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...
std::map< int, std::map< int, std::map< int, std::deque< std::pair< TFeatureID, double > > > > > TQuantizationTable
TMultiResMatchingOutput relocalizeMultiDesc(const mrpt::utils::CImage &image, CFeatureList &baseList, CFeatureList &currentList, TQuantizationTable &qTable, const TMultiResDescOptions &desc_opts, const TMultiResDescMatchOptions &match_opts)
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...
GLsizei const GLchar ** string
Definition: glext.h:4101
A list of visual features, to be used as output by detectors, as input/output by trackers, etc.
Definition: CFeature.h:305
void insertHashCoeffs(const CFeature::Ptr &feat, TQuantizationTable &qTable)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Struct containing the options when computing the multi-resolution SIFT-like descriptors.
void updateBaseList(CFeatureList &baseList, const CFeatureList &currentList, const std::vector< int > &idx)
void saveQTableToFile(const TQuantizationTable &qTable, const std::string &filename)
Struct containing the options when matching multi-resolution SIFT-like descriptors.
void checkScalesAndFindMore(CMatchedFeatureList &baseList, const CFeatureList &currentList, const mrpt::utils::CImage &currentImage, const TMultiResMatchingOutput &output, const TMultiResDescOptions &computeOpts, const TMultiResDescMatchOptions &matchOpts)
GLenum GLint GLint y
Definition: glext.h:3538
void computeMultiOrientations(const mrpt::utils::CImage &image, CFeatureList &list, const TMultiResDescOptions &opts)
Computes the multi-resolution SIFT-like descriptor of a list of features.
GLenum GLint x
Definition: glext.h:3538
TMultiResMatchingOutput matchMultiResolutionFeatures(const CFeatureList &list1, CFeatureList &list2, const mrpt::utils::CImage &rightImage, const TMultiResDescMatchOptions &matchOpts, const TMultiResDescOptions &computeOpts)
Matches two CFeatureList containing mulit-resolution descriptors.
A list of features.
Definition: CFeature.h:504



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019