MRPT  2.0.4
vision/include/mrpt/vision/utils.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
13 #include <mrpt/img/CImage.h>
14 #include <mrpt/img/TStereoCamera.h>
16 #include <mrpt/obs/obs_frwds.h>
17 #include <mrpt/poses/CPose3D.h>
19 #include <mrpt/vision/CFeature.h>
21 #include <mrpt/vision/types.h>
22 
23 namespace mrpt
24 {
25 namespace maps
26 {
27 class CLandmarksMap;
28 }
29 namespace obs
30 {
31 class CObservationVisualLandmarks;
32 }
33 
34 /** Classes for computer vision, detectors, features, etc. \ingroup
35  * mrpt_vision_grp
36  */
37 namespace vision
38 {
39 /** \addtogroup mrpt_vision_grp
40  * @{ */
41 
42 /** Computes the correlation between this image and another one, encapsulating
43  * the openCV function cvMatchTemplate
44  * This implementation reduced computation time.
45  * \param img [IN] The imput image. This function supports
46  * gray-scale (1 channel only) images.
47  * \param patch_img [IN] The "patch" image, which must be equal, or
48  * smaller than "this" image. This function supports gray-scale (1 channel only)
49  * images.
50  * \param x_max [OUT] The x coordinate where it was found the maximun
51  * cross correlation value.
52  * \param y_max [OUT] The y coordinate where it was found the maximun
53  * cross correlation value.
54  * \param max_val [OUT] The maximun value of cross correlation which we
55  * can find
56  * \param x_search_ini [IN] The "x" coordinate of the search window.
57  * \param y_search_ini [IN] The "y" coordinate of the search window.
58  * \param x_search_size [IN] The width of the search window.
59  * \param y_search_size [IN] The height of the search window.
60  * Note: By default, the search area is the whole (this) image.
61  * \sa cross_correlation
62  */
64  const mrpt::img::CImage& img, const mrpt::img::CImage& patch_img,
65  size_t& x_max, size_t& y_max, double& max_val, int x_search_ini = -1,
66  int y_search_ini = -1, int x_search_size = -1, int y_search_size = -1);
67 
68 /** Extract a UNITARY 3D vector in the direction of a 3D point, given from its
69  * (x,y) pixels coordinates, and the camera intrinsic coordinates.
70  * \param xy [IN] Pixels coordinates, from the top-left corner of the
71  * image.
72  * \param A [IN] The 3x3 intrinsic parameters matrix for the camera.
73  * \return The mrpt::math::TPoint3D containing the output unitary vector.
74  * \sa buildIntrinsicParamsMatrix, defaultIntrinsicParamsMatrix, TPixelCoordf
75  */
78 
79 /** Builds the intrinsic parameters matrix A from parameters:
80  * \param focalLengthX [IN] The focal length, in X (horizontal) pixels
81  * \param focalLengthY [IN] The focal length, in Y (vertical) pixels
82  * \param centerX [IN] The image center, horizontal, in pixels
83  * \param centerY [IN] The image center, vertical, in pixels
84  *
85  * <br>This method returns the matrix:
86  <table>
87  <tr><td>f_x</td><td>0</td><td>cX</td> </tr>
88  <tr><td>0</td><td>f_y</td><td>cY</td> </tr>
89  <tr><td>0</td><td>0</td><td>1</td> </tr>
90  </table>
91  * See also the tutorial discussing the <a
92  rhref="http://www.mrpt.org/Camera_Parameters">camera model parameters</a>.
93  * \sa defaultIntrinsicParamsMatrix, pixelTo3D
94  */
96  const double focalLengthX, const double focalLengthY, const double centerX,
97  const double centerY);
98 
99 /** Returns the stored, default intrinsic params matrix for a given camera:
100  * \param camIndex [IN] Posible values are listed next.
101  * \param resolutionX [IN] The number of pixel columns
102  * \param resolutionY [IN] The number of pixel rows
103  *
104  * The matrix is generated for the indicated camera resolution configuration.
105  * The following table summarizes the current supported cameras and the values
106  as
107  * ratios of the corresponding horz. or vert. resolution:<br>
108 
109  <center><table>
110  <tr>
111  <td><center><b>camIndex</b></center></td>
112  <td><center><b>Manufacturer</b></center></td>
113  <td><center><b>Camera model</b></center></td>
114  <td><center><b>fx</b></center></td>
115  <td><center><b>fy</b></center></td>
116  <td><center><b>cx</b></center></td>
117  <td><center><b>cy</b></center></td>
118  </tr>
119 
120  <tr>
121  <td><center>0</center></td>
122  <td><center>Point Grey Research</center></td>
123  <td><center>Bumblebee</center></td>
124  <td><center>0.79345</center></td>
125  <td><center>1.05793</center></td>
126  <td><center>0.55662</center></td>
127  <td><center>0.52692</center></td>
128  </tr>
129 
130  <tr>
131  <td><center>1</center></td>
132  <td><center>Sony</center></td>
133  <td><center>???</center></td>
134  <td><center>0.95666094</center></td>
135  <td><center>1.3983423f</center></td>
136  <td><center>0.54626328f</center></td>
137  <td><center>0.4939191f</center></td>
138  </tr>
139  </table>
140  </center>
141 
142  * \sa buildIntrinsicParamsMatrix, pixelTo3D
143  */
145  unsigned int camIndex = 0, unsigned int resolutionX = 320,
146  unsigned int resolutionY = 240);
147 
148 /** Computes the mean squared distance between a set of 3D correspondences
149  * ...
150  */
151 double computeMsd(
152  const mrpt::tfest::TMatchingPairList& list, const poses::CPose3D& Rt);
153 
154 /** Transform two clouds of 3D points into a matched list of points
155  * ...
156  */
161 
162 /** Computes the main orientation of a set of points with an image (for using in
163  * SIFT-based algorithms)
164  * \param image [IN] The input image.
165  * \param x [IN] A vector containing the 'x' coordinates of the image
166  * points.
167  * \param y [IN] A vector containing the 'y' coordinates of the image
168  * points.
169  * \return The main orientation of the image point.
170  */
172  const mrpt::img::CImage& image, unsigned int x, unsigned int y);
173 
174 /** Normalizes the brigthness and contrast of an image by setting its mean value
175  * to zero and its standard deviation to unit.
176  * \param image [IN] The input image.
177  * \param nimage [OUTPUT] The new normalized image.
178  */
179 void normalizeImage(const mrpt::img::CImage& image, mrpt::img::CImage& nimage);
180 
181 /** Find the matches between two lists of features which must be of the same
182  * type.
183  * \param list1 [IN] One list.
184  * \param list2 [IN] Other list.
185  * \param matches [OUT] A vector of pairs of correspondences.
186  * \param options [IN] A struct containing matching options
187  * \return Returns the number of matched pairs of features.
188  */
189 size_t matchFeatures(
190  const CFeatureList& list1, const CFeatureList& list2,
191  CMatchedFeatureList& matches,
192  const TMatchingOptions& options = TMatchingOptions(),
194 
195 /** Calculates the Sum of Absolutes Differences (range [0,1]) between two
196  * patches. Both patches must have the same size.
197  * \param mList [IN] The list of matched features.
198  * \param mask1 [OUT] The output mask for left features.
199  * \param mask2 [OUT] The output mask for right features.
200  * \param wSize [IN] The value of the masking window for each features.
201  * \exception if mList.size() = 0
202  */
203 void generateMask(
204  const CMatchedFeatureList& mList, mrpt::math::CMatrixBool& mask1,
205  mrpt::math::CMatrixBool& mask2, int wSize = 10);
206 
207 /** Calculates the Sum of Absolutes Differences (range [0,1]) between two
208  * patches. Both patches must have the same size.
209  * \param patch1 [IN] One patch.
210  * \param patch2 [IN] The other patch.
211  * \return The value of computed SAD normalized to [0,1]
212  */
213 double computeSAD(
214  const mrpt::img::CImage& patch1, const mrpt::img::CImage& patch2);
215 
216 /** Draw rectangles around each of the features on a copy of the input image.
217  * \param inImg [IN] The input image where to draw the features.
218  * \param theList [IN] The list of features.
219  * \param outImg [OUT] The copy of the input image with the marked
220  * features.
221  */
222 void addFeaturesToImage(
223  const mrpt::img::CImage& inImg, const CFeatureList& theList,
224  mrpt::img::CImage& outImg);
225 
227  const CMatchedFeatureList& matches,
228  const mrpt::img::TStereoCamera& stereo_camera,
229  std::vector<mrpt::math::TPoint3D>& out_points);
230 
231 /** Computes the 3D position of a set of matched features from their coordinates
232  * in the images. The list have to be matched in order, e.g.
233  * leftList[0]<->rightList[0]
234  * \param leftList [IN] The left list of features.
235  * \param rightList [IN] The right list of features.
236  * \param vP3D [OUT] A vector of mrpt::math::TPoint3D containing the
237  * 3D positions of the projected points.
238  * \param params [IN] The intrinsic and extrinsic parameters of the
239  * stereo pair.
240  */
242  const CFeatureList& leftList, const CFeatureList& rightList,
243  std::vector<mrpt::math::TPoint3D>& vP3D,
245 
246 /** Computes the 3D position of a particular matched feature.
247  * \param leftList [IN] The left feature.
248  * \param rightList [IN] The right feature.
249  * \param vP3D [OUT] The 3D position of the projected point.
250  * \param params [IN] The intrinsic and extrinsic parameters of the
251  * stereo pair.
252  */
254  const CFeature& leftFeat, const CFeature& rightFeat,
257 
258 /** Project a list of matched features into the 3D space, using the provided
259  * parameters of the stereo system
260  * \param mfList [IN/OUT] The list of matched features. Features which
261  * yields a 3D point outside the area defined in TStereoSystemParams are removed
262  * from the lists.
263  * \param param [IN] The parameters of the stereo system.
264  * \param landmarks [OUT] A map containing the projected landmarks.
265  * \sa TStereoSystemParams, CLandmarksMap
266  */
268  CMatchedFeatureList& mfList, const TStereoSystemParams& param,
269  mrpt::maps::CLandmarksMap& landmarks);
270 
271 /** Project a pair of feature lists into the 3D space, using the provided
272  *options for the stereo system. The matches must be in order,
273  * i.e. leftList[0] corresponds to rightList[0] and so on. Features which
274  *yields a 3D point outside the area defined in TStereoSystemParams are removed
275  *from the lists.
276  * \param leftList [IN/OUT] The left list of matched features.
277  * \param rightList [IN/OUT] The right list of matched features.
278  * \param param [IN] The options of the stereo system.
279  * \param landmarks (OUT] A map containing the projected landmarks.
280  * \sa TStereoSystemParams, CLandmarksMap
281  */
283  CFeatureList& leftList, CFeatureList& rightList,
284  const TStereoSystemParams& param, mrpt::maps::CLandmarksMap& landmarks);
285 
286 /** Converts a stereo images observation into a bearing and range observation.
287  \param inObs [IN] The input stereo images observation.
288  \param sg [IN] The sigma of the row, col, and disparity variables
289  involved in the feature detection.
290  \param outObs [OUT] The output bearing and range observation
291  (including covariances).
292 */
293 void StereoObs2BRObs(
295  const std::vector<double>& sg, mrpt::obs::CObservationBearingRange& outObs);
296 
297 /** Converts a matched feature list into a bearing and range observation (some
298  of the stereo camera system must be provided).
299  \param inMatches [IN] The input list of matched features.
300  \param intrinsicParams [IN] The intrisic params of the reference
301  (left) camera of the stereo system.
302  \param baseline [IN] The distance among the X axis of the
303  right camera wrt the reference (left) camera.
304  \param sg [IN] The sigma of the row, col, and disparity
305  variables involved in the feature detection.
306  \param outObs [OUT] The output bearing and range observation
307  (including covariances).
308 */
309 void StereoObs2BRObs(
310  const CMatchedFeatureList& inMatches,
311  const mrpt::math::CMatrixDouble33& intrinsicParams, double baseline,
312  const mrpt::poses::CPose3D& sensorPose, const std::vector<double>& sg,
314 
315 /** Converts a CObservationVisualLandmarks into a bearing and range observation
316  (without any covariances). Fields of view are not computed.
317  \param inObs [IN] The input observation.
318  \param sg [IN] The sigma of the row, col, and disparity
319  variables involved in the feature detection.
320  \param outObs [OUT] The output bearing and range observation.
321 */
322 void StereoObs2BRObs(
324  const std::vector<double>& sg, mrpt::obs::CObservationBearingRange& outObs);
325 
326 /** Converts a CObservationVisualLandmarks into a bearing and range observation
327  (without any covariances). Fields of view are not computed.
328  \param inObs [IN] The input observation.
329  \param outObs [OUT] The output bearing and range observation.
330 */
331 void StereoObs2BRObs(
334 
335 /** Computes a pair of x-and-y maps for stereo rectification from a pair of
336 cameras and the relative pose of the second one wrt the first one.
337  \param cam1, cam2 [IN] The pair of involved cameras
338  \param rightCameraPose [IN] The change in pose of the second camera
339 wrt the first one
340  \param outMap1x,outMap1y [OUT] The x-and-y maps corresponding to cam1
341 (should be converted to *cv::Mat)
342  \param outMap2x,outMap2y [OUT] The x-and-y maps corresponding to cam2
343 (should be converted to *cv::Mat)
344 * \sa An easier to use class for stereo rectification
345 mrpt::vision::CStereoRectifyMap
346 */
348  const mrpt::img::TCamera& cam1, const mrpt::img::TCamera& cam2,
349  const mrpt::poses::CPose3D& rightCameraPose, void* outMap1x, void* outMap1y,
350  void* outMap2x, void* outMap2y);
351 
352 /** @} */ // end of grouping
353 
354 } // namespace vision
355 } // namespace mrpt
void projectMatchedFeature(const CFeature &leftFeat, const CFeature &rightFeat, mrpt::math::TPoint3D &p3D, const TStereoSystemParams &params=TStereoSystemParams())
Computes the 3D position of a particular matched feature.
void StereoObs2BRObs(const mrpt::obs::CObservationStereoImages &inObs, const std::vector< double > &sg, mrpt::obs::CObservationBearingRange &outObs)
Converts a stereo images observation into a bearing and range observation.
Declares a class derived from "CObservation" that stores a Landmarks Map as seen from a stereo camera...
mrpt::vision::TStereoCalibParams params
A pair (x,y) of pixel coordinates (subpixel resolution).
Definition: TPixelCoord.h:18
void normalizeImage(const mrpt::img::CImage &image, mrpt::img::CImage &nimage)
Normalizes the brigthness and contrast of an image by setting its mean value to zero and its standard...
A class for storing a map of 3D probabilistic landmarks.
Definition: CLandmarksMap.h:74
Parameters associated to a stereo system.
A list of TMatchingPair.
Definition: TMatchingPair.h:70
Observation class for either a pair of left+right or left+disparity images from a stereo camera...
Parameters for the Brown-Conrady camera lens distortion model.
Definition: TCamera.h:26
A generic 2D feature from an image, extracted with CFeatureExtraction Each feature may have one or mo...
Definition: CFeature.h:53
double computeMsd(const mrpt::tfest::TMatchingPairList &list, const poses::CPose3D &Rt)
Computes the mean squared distance between a set of 3D correspondences ...
void computeStereoRectificationMaps(const mrpt::img::TCamera &cam1, const mrpt::img::TCamera &cam2, const mrpt::poses::CPose3D &rightCameraPose, void *outMap1x, void *outMap1y, void *outMap2x, void *outMap2y)
Computes a pair of x-and-y maps for stereo rectification from a pair of cameras and the relative pose...
A list of visual features, to be used as output by detectors, as input/output by trackers, etc.
Definition: CFeature.h:275
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
float computeMainOrientation(const mrpt::img::CImage &image, unsigned int x, unsigned int y)
Computes the main orientation of a set of points with an image (for using in SIFT-based algorithms) ...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
size_t matchFeatures(const CFeatureList &list1, const CFeatureList &list2, CMatchedFeatureList &matches, const TMatchingOptions &options=TMatchingOptions(), const TStereoSystemParams &params=TStereoSystemParams())
Find the matches between two lists of features which must be of the same type.
This observation represents a number of range-bearing value pairs, each one for a detected landmark...
A structure containing options for the matching.
void generateMask(const CMatchedFeatureList &mList, mrpt::math::CMatrixBool &mask1, mrpt::math::CMatrixBool &mask2, int wSize=10)
Calculates the Sum of Absolutes Differences (range [0,1]) between two patches.
double computeSAD(const mrpt::img::CImage &patch1, const mrpt::img::CImage &patch2)
Calculates the Sum of Absolutes Differences (range [0,1]) between two patches.
void cloudsToMatchedList(const mrpt::obs::CObservationVisualLandmarks &cloud1, const mrpt::obs::CObservationVisualLandmarks &cloud2, mrpt::tfest::TMatchingPairList &outList)
Transform two clouds of 3D points into a matched list of points ...
void openCV_cross_correlation(const mrpt::img::CImage &img, const mrpt::img::CImage &patch_img, size_t &x_max, size_t &y_max, double &max_val, int x_search_ini=-1, int y_search_ini=-1, int x_search_size=-1, int y_search_size=-1)
Computes the correlation between this image and another one, encapsulating the openCV function cvMatc...
void projectMatchedFeatures(const CMatchedFeatureList &matches, const mrpt::img::TStereoCamera &stereo_camera, std::vector< mrpt::math::TPoint3D > &out_points)
This template class provides the basic functionality for a general 2D any-size, resizable container o...
mrpt::math::CMatrixDouble33 defaultIntrinsicParamsMatrix(unsigned int camIndex=0, unsigned int resolutionX=320, unsigned int resolutionY=240)
Returns the stored, default intrinsic params matrix for a given camera:
Structure to hold the parameters of a pinhole stereo camera model.
Definition: TStereoCamera.h:23
mrpt::math::TPoint3D pixelTo3D(const mrpt::img::TPixelCoordf &xy, const mrpt::math::CMatrixDouble33 &A)
Extract a UNITARY 3D vector in the direction of a 3D point, given from its (x,y) pixels coordinates...
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148
mrpt::math::CMatrixDouble33 buildIntrinsicParamsMatrix(const double focalLengthX, const double focalLengthY, const double centerX, const double centerY)
Builds the intrinsic parameters matrix A from parameters:
A list of features.
Definition: CFeature.h:494
void addFeaturesToImage(const mrpt::img::CImage &inImg, const CFeatureList &theList, mrpt::img::CImage &outImg)
Draw rectangles around each of the features on a copy of the input image.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020