Main MRPT website > C++ reference
MRPT logo
vision/include/mrpt/vision/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-2014, 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_vision_utils_H
11 #define mrpt_vision_utils_H
12 
13 #include <mrpt/vision/CFeature.h>
14 #include <mrpt/utils/CImage.h>
19 #include <mrpt/poses/CPose3D.h>
20 #include <mrpt/vision/types.h>
22 
24 
25 namespace mrpt
26 {
27  namespace slam
28  {
29  class CObservationStereoImages;
30  class CObservationBearingRange;
31  class CLandmarksMap;
32  class CObservationVisualLandmarks;
33  }
34 
35  /** Classes for computer vision, detectors, features, etc. \ingroup mrpt_vision_grp
36  */
37  namespace vision
38  {
39  using std::vector;
40  using namespace mrpt::slam;
41  using namespace mrpt::math;
42  using namespace mrpt::utils;
43 
44  /** \addtogroup mrpt_vision_grp
45  * @{ */
46 
47  /** Computes the correlation between this image and another one, encapsulating the openCV function cvMatchTemplate
48  * This implementation reduced computation time.
49  * \param img [IN] The imput image. This function supports gray-scale (1 channel only) images.
50  * \param patch_img [IN] The "patch" image, which must be equal, or smaller than "this" image. This function supports gray-scale (1 channel only) images.
51  * \param x_max [OUT] The x coordinate where it was found the maximun cross correlation value.
52  * \param y_max [OUT] The y coordinate where it was found the maximun cross correlation value.
53  * \param max_val [OUT] The maximun value of cross correlation which we can find
54  * \param x_search_ini [IN] The "x" coordinate of the search window.
55  * \param y_search_ini [IN] The "y" coordinate of the search window.
56  * \param x_search_size [IN] The width of the search window.
57  * \param y_search_size [IN] The height of the search window.
58  * Note: By default, the search area is the whole (this) image.
59  * \sa cross_correlation
60  */
62  const CImage & img,
63  const CImage & patch_img,
64  size_t & x_max,
65  size_t & y_max,
66  double & max_val,
67  int x_search_ini=-1,
68  int y_search_ini=-1,
69  int x_search_size=-1,
70  int y_search_size=-1);
71 
72  /** Invert an image using OpenCV function
73  *
74  */
75  void VISION_IMPEXP flip(
76  CImage & img);
77 
78  /** Extract a UNITARY 3D vector in the direction of a 3D point, given from its (x,y) pixels coordinates, and the camera intrinsic coordinates.
79  * \param xy [IN] Pixels coordinates, from the top-left corner of the image.
80  * \param A [IN] The 3x3 intrinsic parameters matrix for the camera.
81  * \return The TPoint3D containing the output unitary vector.
82  * \sa buildIntrinsicParamsMatrix, defaultIntrinsicParamsMatrix, TPixelCoordf
83  */
85  const TPixelCoordf & xy,
86  const CMatrixDouble33 & A);
87 
88  /** Builds the intrinsic parameters matrix A from parameters:
89  * \param focalLengthX [IN] The focal length, in X (horizontal) pixels
90  * \param focalLengthY [IN] The focal length, in Y (vertical) pixels
91  * \param centerX [IN] The image center, horizontal, in pixels
92  * \param centerY [IN] The image center, vertical, in pixels
93  *
94  * <br>This method returns the matrix:
95  <table>
96  <tr><td>f_x</td><td>0</td><td>cX</td> </tr>
97  <tr><td>0</td><td>f_y</td><td>cY</td> </tr>
98  <tr><td>0</td><td>0</td><td>1</td> </tr>
99  </table>
100  * See also the tutorial discussing the <a rhref="http://www.mrpt.org/Camera_Parameters">camera model parameters</a>.
101  * \sa defaultIntrinsicParamsMatrix, pixelTo3D
102  */
104  const double focalLengthX,
105  const double focalLengthY,
106  const double centerX,
107  const double centerY);
108 
109  /** Returns the stored, default intrinsic params matrix for a given camera:
110  * \param camIndex [IN] Posible values are listed next.
111  * \param resolutionX [IN] The number of pixel columns
112  * \param resolutionY [IN] The number of pixel rows
113  *
114  * The matrix is generated for the indicated camera resolution configuration.
115  * The following table summarizes the current supported cameras and the values as
116  * ratios of the corresponding horz. or vert. resolution:<br>
117 
118  <center><table>
119  <tr>
120  <td><center><b>camIndex</b></center></td>
121  <td><center><b>Manufacturer</b></center></td>
122  <td><center><b>Camera model</b></center></td>
123  <td><center><b>fx</b></center></td>
124  <td><center><b>fy</b></center></td>
125  <td><center><b>cx</b></center></td>
126  <td><center><b>cy</b></center></td>
127  </tr>
128 
129  <tr>
130  <td><center>0</center></td>
131  <td><center>Point Grey Research</center></td>
132  <td><center>Bumblebee</center></td>
133  <td><center>0.79345</center></td>
134  <td><center>1.05793</center></td>
135  <td><center>0.55662</center></td>
136  <td><center>0.52692</center></td>
137  </tr>
138 
139  <tr>
140  <td><center>1</center></td>
141  <td><center>Sony</center></td>
142  <td><center>???</center></td>
143  <td><center>0.95666094</center></td>
144  <td><center>1.3983423f</center></td>
145  <td><center>0.54626328f</center></td>
146  <td><center>0.4939191f</center></td>
147  </tr>
148  </table>
149  </center>
150 
151  * \sa buildIntrinsicParamsMatrix, pixelTo3D
152  */
154  unsigned int camIndex = 0,
155  unsigned int resolutionX = 320,
156  unsigned int resolutionY = 240 );
157 
158  /** Explore the feature list and removes features which are in the same coordinates
159  * \param list [IN] The list of features.
160  */
162  CFeatureList & list );
163 
164  /** Search for correspondences which are not in the same row and deletes them
165  * \param leftList [IN/OUT] The left list of matched features.
166  * \param rightList [IN/OUT] The right list of matched features.
167  * \param threshold [IN] The tolerance value for the row checking: valid matched are within this threshold.
168  */
170  CFeatureList & leftList,
171  CFeatureList & rightList,
172  float threshold = 1.0);
173 
174  /** Computes the dispersion of the features in the image
175  * \param list [IN] Input list of features
176  * \param std [OUT] 2 element vector containing the standard deviations in the 'x' and 'y' coordinates.
177  * \param mean [OUT] 2 element vector containing the mean in the 'x' and 'y' coordinates.
178  */
180  const CFeatureList & list,
181  CVectorFloat & std,
182  CVectorFloat & mean );
183 
184  /** Computes the mean squared distance between a set of 3D correspondences
185  * ...
186  */
187  double VISION_IMPEXP computeMsd(
188  const TMatchingPairList & list,
189  const poses::CPose3D & Rt );
190 
191  /** Transform two clouds of 3D points into a matched list of points
192  * ...
193  */
195  const CObservationVisualLandmarks & cloud1,
196  const CObservationVisualLandmarks & cloud2,
197  TMatchingPairList & outList);
198 
199  /** Computes the main orientation of a set of points with an image (for using in SIFT-based algorithms)
200  * \param image [IN] The input image.
201  * \param x [IN] A vector containing the 'x' coordinates of the image points.
202  * \param y [IN] A vector containing the 'y' coordinates of the image points.
203  * \return The main orientation of the image point.
204  */
206  const CImage & image,
207  unsigned int x,
208  unsigned int y );
209 
210  /** Normalizes the brigthness and contrast of an image by setting its mean value to zero and its standard deviation to unit.
211  * \param image [IN] The input image.
212  * \param nimage [OUTPUT] The new normalized image.
213  */
215  const CImage & image,
216  CImage & nimage );
217 
218  /** Find the matches between two lists of features which must be of the same type.
219  * \param list1 [IN] One list.
220  * \param list2 [IN] Other list.
221  * \param matches [OUT] A vector of pairs of correspondences.
222  * \param options [IN] A struct containing matching options
223  * \return Returns the number of matched pairs of features.
224  */
226  const CFeatureList & list1,
227  const CFeatureList & list2,
228  CMatchedFeatureList & matches,
229  const TMatchingOptions & options = TMatchingOptions(),
230  const TStereoSystemParams & params = TStereoSystemParams() );
231 
232  /** Calculates the Sum of Absolutes Differences (range [0,1]) between two patches. Both patches must have the same size.
233  * \param mList [IN] The list of matched features.
234  * \param mask1 [OUT] The output mask for left features.
235  * \param mask2 [OUT] The output mask for right features.
236  * \param wSize [IN] The value of the masking window for each features.
237  * \exception if mList.size() = 0
238  */
240  const CMatchedFeatureList & mList,
241  mrpt::math::CMatrixBool & mask1,
242  mrpt::math::CMatrixBool & mask2,
243  int wSize = 10 );
244 
245  /** Calculates the Sum of Absolutes Differences (range [0,1]) between two patches. Both patches must have the same size.
246  * \param patch1 [IN] One patch.
247  * \param patch2 [IN] The other patch.
248  * \return The value of computed SAD normalized to [0,1]
249  */
250  double VISION_IMPEXP computeSAD(
251  const CImage & patch1,
252  const CImage & patch2 );
253 
254  /** Draw rectangles around each of the features on a copy of the input image.
255  * \param inImg [IN] The input image where to draw the features.
256  * \param theList [IN] The list of features.
257  * \param outImg [OUT] The copy of the input image with the marked features.
258  */
260  const CImage & inImg,
261  const CFeatureList & theList,
262  CImage & outImg );
263 
265  const CMatchedFeatureList & matches,
266  const mrpt::utils::TStereoCamera & stereo_camera,
267  vector<TPoint3D> & out_points );
268 
269  /** Computes the 3D position of a set of matched features from their coordinates in the images. The list have to be matched in order, e.g. leftList[0]<->rightList[0]
270  * \param leftList [IN] The left list of features.
271  * \param rightList [IN] The right list of features.
272  * \param vP3D [OUT] A vector of TPoint3D containing the 3D positions of the projected points.
273  * \param params [IN] The intrinsic and extrinsic parameters of the stereo pair.
274  */
276  const CFeatureList & leftList,
277  const CFeatureList & rightList,
278  vector<TPoint3D> & vP3D,
279  const TStereoSystemParams & params = TStereoSystemParams() );
280 
281  /** Computes the 3D position of a particular matched feature.
282  * \param leftList [IN] The left feature.
283  * \param rightList [IN] The right feature.
284  * \param vP3D [OUT] The 3D position of the projected point.
285  * \param params [IN] The intrinsic and extrinsic parameters of the stereo pair.
286  */
288  const CFeaturePtr & leftFeat,
289  const CFeaturePtr & rightFeat,
290  TPoint3D & p3D,
291  const TStereoSystemParams & params = TStereoSystemParams() );
292 
293  /** Project a list of matched features into the 3D space, using the provided parameters of the stereo system
294  * \param mfList [IN/OUT] The list of matched features. Features which yields a 3D point outside the area defined in TStereoSystemParams are removed from the lists.
295  * \param param [IN] The parameters of the stereo system.
296  * \param landmarks [OUT] A map containing the projected landmarks.
297  * \sa TStereoSystemParams, CLandmarksMap
298  */
300  CMatchedFeatureList & mfList,
301  const TStereoSystemParams & param,
302  CLandmarksMap & landmarks );
303 
304  /** Project a pair of feature lists into the 3D space, using the provided options for the stereo system. The matches must be in order,
305  * i.e. leftList[0] corresponds to rightList[0] and so on. Features which yields a 3D point outside the area defined in TStereoSystemParams are removed from the lists.
306  * \param leftList [IN/OUT] The left list of matched features.
307  * \param rightList [IN/OUT] The right list of matched features.
308  * \param param [IN] The options of the stereo system.
309  * \param landmarks (OUT] A map containing the projected landmarks.
310  * \sa TStereoSystemParams, CLandmarksMap
311  */
313  CFeatureList & leftList,
314  CFeatureList & rightList,
315  const TStereoSystemParams & param,
316  CLandmarksMap & landmarks );
317 
318  /** Converts a stereo images observation into a bearing and range observation.
319  \param inObs [IN] The input stereo images observation.
320  \param sg [IN] The sigma of the row, col, and disparity variables involved in the feature detection.
321  \param outObs [OUT] The output bearing and range observation (including covariances).
322  */
324  const CObservationStereoImages & inObs,
325  const vector<double> & sg,
326  CObservationBearingRange & outObs );
327 
328  /** Converts a matched feature list into a bearing and range observation (some of the stereo camera system must be provided).
329  \param inMatches [IN] The input list of matched features.
330  \param intrinsicParams [IN] The intrisic params of the reference (left) camera of the stereo system.
331  \param baseline [IN] The distance among the X axis of the right camera wrt the reference (left) camera.
332  \param sg [IN] The sigma of the row, col, and disparity variables involved in the feature detection.
333  \param outObs [OUT] The output bearing and range observation (including covariances).
334  */
336  const CMatchedFeatureList & inMatches,
337  const CMatrixDouble33 & intrinsicParams,
338  const double & baseline,
339  const mrpt::poses::CPose3D & sensorPose,
340  const vector<double> & sg,
341  CObservationBearingRange & outObs );
342 
343  /** Converts a CObservationVisualLandmarks into a bearing and range observation (without any covariances). Fields of view are not computed.
344  \param inObs [IN] The input observation.
345  \param sg [IN] The sigma of the row, col, and disparity variables involved in the feature detection.
346  \param outObs [OUT] The output bearing and range observation.
347  */
349  const CObservationStereoImages & inObs,
350  const vector<double> & sg,
351  CObservationBearingRange & outObs );
352 
353  /** Converts a CObservationVisualLandmarks into a bearing and range observation (without any covariances). Fields of view are not computed.
354  \param inObs [IN] The input observation.
355  \param outObs [OUT] The output bearing and range observation.
356  */
358  const CObservationVisualLandmarks & inObs,
359  CObservationBearingRange & outObs );
360 
361  /** Computes a pair of x-and-y maps for stereo rectification from a pair of cameras and the relative pose of the second one wrt the first one.
362  \param cam1, cam2 [IN] The pair of involved cameras
363  \param rightCameraPose [IN] The change in pose of the second camera wrt the first one
364  \param outMap1x,outMap1y [OUT] The x-and-y maps corresponding to cam1 (should be converted to *cv::Mat)
365  \param outMap2x,outMap2y [OUT] The x-and-y maps corresponding to cam2 (should be converted to *cv::Mat)
366  * \sa An easier to use class for stereo rectification mrpt::vision::CStereoRectifyMap
367  */
369  const TCamera & cam1,
370  const TCamera & cam2,
371  const poses::CPose3D & rightCameraPose,
372  void *outMap1x,
373  void *outMap1y,
374  void *outMap2x,
375  void *outMap2y );
376 
377 
378  /** @} */ // end of grouping
379 
380  } // end-namespace-vision
381 } // end-namespace-mrpt
382 
383 
384 #endif
A class for storing a map of 3D probabilistic landmarks.
Definition: CLandmarksMap.h:63
A pair (x,y) of pixel coordinates (subpixel resolution).
Definition: TPixelCoord.h:21
float VISION_IMPEXP computeMainOrientation(const 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) ...
CMatrixDouble33 VISION_IMPEXP buildIntrinsicParamsMatrix(const double focalLengthX, const double focalLengthY, const double centerX, const double centerY)
Builds the intrinsic parameters matrix A from parameters:
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
void VISION_IMPEXP getDispersion(const CFeatureList &list, CVectorFloat &std, CVectorFloat &mean)
Computes the dispersion of the features in the image.
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:97
Declares a class derived from "CObservation" that stores a Landmarks Map as seen from a stereo camera...
void VISION_IMPEXP projectMatchedFeature(const CFeaturePtr &leftFeat, const CFeaturePtr &rightFeat, TPoint3D &p3D, const TStereoSystemParams &params=TStereoSystemParams())
Computes the 3D position of a particular matched feature.
This observation represents a number of range-bearing value pairs, each one for a detected landmark...
double VISION_IMPEXP computeMsd(const TMatchingPairList &list, const poses::CPose3D &Rt)
Computes the mean squared distance between a set of 3D correspondences ...
STL namespace.
void VISION_IMPEXP projectMatchedFeatures(const CMatchedFeatureList &matches, const mrpt::utils::TStereoCamera &stereo_camera, vector< TPoint3D > &out_points)
This namespace contains algorithms for SLAM, localization, map building, representation of robot's ac...
Structure to hold the parameters of a pinhole stereo camera model.
Definition: TStereoCamera.h:25
void VISION_IMPEXP addFeaturesToImage(const CImage &inImg, const CFeatureList &theList, CImage &outImg)
Draw rectangles around each of the features on a copy of the input image.
void VISION_IMPEXP normalizeImage(const CImage &image, CImage &nimage)
Normalizes the brigthness and contrast of an image by setting its mean value to zero and its standard...
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
Definition: CArray.h:18
void VISION_IMPEXP cloudsToMatchedList(const CObservationVisualLandmarks &cloud1, const CObservationVisualLandmarks &cloud2, TMatchingPairList &outList)
Transform two clouds of 3D points into a matched list of points ...
TPoint3D VISION_IMPEXP pixelTo3D(const TPixelCoordf &xy, const CMatrixDouble33 &A)
Extract a UNITARY 3D vector in the direction of a 3D point, given from its (x,y) pixels coordinates...
void VISION_IMPEXP flip(CImage &img)
Invert an image using OpenCV function.
A list of TMatchingPair.
Definition: TMatchingPair.h:66
void VISION_IMPEXP computeStereoRectificationMaps(const TCamera &cam1, const TCamera &cam2, const 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...
double VISION_IMPEXP computeSAD(const CImage &patch1, const CImage &patch2)
Calculates the Sum of Absolutes Differences (range [0,1]) between two patches.
void VISION_IMPEXP rowChecking(CFeatureList &leftList, CFeatureList &rightList, float threshold=1.0)
Search for correspondences which are not in the same row and deletes them.
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:51
This template class provides the basic functionality for a general 2D any-size, resizable container o...
Observation class for either a pair of left+right or left+disparity images from a stereo camera...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void VISION_IMPEXP StereoObs2BRObs(const CObservationStereoImages &inObs, const vector< double > &sg, CObservationBearingRange &outObs)
Converts a stereo images observation into a bearing and range observation.
void VISION_IMPEXP openCV_cross_correlation(const CImage &img, const 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...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:69
void VISION_IMPEXP deleteRepeatedFeats(CFeatureList &list)
Explore the feature list and removes features which are in the same coordinates.
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
Lightweight 3D point.
CMatrixDouble33 VISION_IMPEXP defaultIntrinsicParamsMatrix(unsigned int camIndex=0, unsigned int resolutionX=320, unsigned int resolutionY=240)
Returns the stored, default intrinsic params matrix for a given camera:
void VISION_IMPEXP 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.
Structure to hold the parameters of a pinhole camera model.
Definition: TCamera.h:31
size_t VISION_IMPEXP 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.



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014