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



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018