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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020