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