00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2010 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 00029 #ifndef mrpt_vision_utils_H 00030 #define mrpt_vision_utils_H 00031 00032 #include <mrpt/vision/CFeature.h> 00033 #include <mrpt/utils/CImage.h> 00034 #include <mrpt/math/utils.h> 00035 #include <mrpt/utils/CLoadableOptions.h> 00036 #include <mrpt/utils/TMatchingPair.h> 00037 #include <mrpt/poses/CPose3D.h> 00038 #include <mrpt/poses/CPoint2D.h> 00039 #include <mrpt/poses/CPoint3D.h> 00040 #include <mrpt/slam/CLandmarksMap.h> 00041 #include <mrpt/slam/CObservationVisualLandmarks.h> 00042 00043 #include <mrpt/vision/types.h> 00044 #include <mrpt/vision/chessboard_camera_calib.h> 00045 00046 #include <mrpt/vision/link_pragmas.h> 00047 00048 namespace mrpt 00049 { 00050 namespace slam 00051 { 00052 class CObservationStereoImages; 00053 class CObservationBearingRange; 00054 } 00055 00056 /** Classes for computer vision, detectors, features, etc. 00057 */ 00058 namespace vision 00059 { 00060 using namespace mrpt::slam; 00061 using namespace mrpt::math; 00062 using namespace mrpt::utils; 00063 00064 /** Computes the correlation between this image and another one, encapsulating the openCV function cvMatchTemplate 00065 * This implementation reduced computation time. 00066 * \param patch_img The "patch" image, which must be equal, or smaller than "this" image. This function supports gray-scale (1 channel only) images. 00067 * \param x_search_ini The "x" coordinate of the search window. 00068 * \param y_search_ini The "y" coordinate of the search window. 00069 * \param x_search_size The width of the search window. 00070 * \param y_search_size The height of the search window. 00071 * \param x_max The x coordinate where found the maximun cross correlation value. 00072 * \param y_max The y coordinate where found the maximun cross correlation value 00073 * \param max_val The maximun value of cross correlation which we can find 00074 * Note: By default, the search area is the whole (this) image. 00075 * \sa cross_correlation 00076 */ 00077 void VISION_IMPEXP openCV_cross_correlation( 00078 const CImage &img, 00079 const CImage &patch_img, 00080 size_t &x_max, 00081 size_t &y_max, 00082 double &max_val, 00083 int x_search_ini=-1, 00084 int y_search_ini=-1, 00085 int x_search_size=-1, 00086 int y_search_size=-1); 00087 00088 /** Invert an image using OpenCV function 00089 * 00090 */ 00091 void VISION_IMPEXP flip(CImage &img); 00092 00093 /** Extract a UNITARY 3D vector in the direction of a 3D point, given from its (x,y) pixels coordinates, and the camera intrinsic coordinates. 00094 * \param x Pixels coordinates, from the top-left corner of the image. 00095 * \param y Pixels coordinates, from the top-left corner of the image. 00096 * \param A The 3x3 intrinsic parameters matrix for the camera. 00097 * 00098 * \sa buildIntrinsicParamsMatrix, defaultIntrinsicParamsMatrix 00099 */ 00100 TPoint3D VISION_IMPEXP pixelTo3D( const vision::TPixelCoordf &xy, const CMatrixDouble33 &A); 00101 00102 /** Builds the intrinsic parameters matrix A from parameters: 00103 * \param focalLengthX The focal length, in X (horizontal) pixels 00104 * \param focalLengthY The focal length, in Y (vertical) pixels 00105 * \param centerX The image center, horizontal, in pixels 00106 * \param centerY The image center, vertical, in pixels 00107 * 00108 * <br>This method returns the matrix: 00109 <table> 00110 <tr><td>f_x</td><td>0</td><td>cX</td> </tr> 00111 <tr><td>0</td><td>f_y</td><td>cY</td> </tr> 00112 <tr><td>0</td><td>0</td><td>1</td> </tr> 00113 </table> 00114 * See also the tutorial discussing the <a rhref="http://www.mrpt.org/Camera_Parameters">camera model parameters</a>. 00115 * \sa defaultIntrinsicParamsMatrix, pixelTo3D 00116 */ 00117 CMatrixDouble33 VISION_IMPEXP buildIntrinsicParamsMatrix( 00118 const double focalLengthX, 00119 const double focalLengthY, 00120 const double centerX, 00121 const double centerY); 00122 00123 /** Returns the stored, default intrinsic params matrix for a given camera: 00124 * \param camIndex Posible values are listed next. 00125 * \param resolutionX The number of pixel columns 00126 * \param resolutionY The number of pixel rows 00127 * 00128 * The matrix is generated for the indicated camera resolution configuration. 00129 * The following table summarizes the current supported cameras and the values as 00130 * ratios of the corresponding horz. or vert. resolution:<br> 00131 00132 <center><table> 00133 <tr> 00134 <td><center><b>camIndex</b></center></td> 00135 <td><center><b>Manufacturer</b></center></td> 00136 <td><center><b>Camera model</b></center></td> 00137 <td><center><b>fx</b></center></td> 00138 <td><center><b>fy</b></center></td> 00139 <td><center><b>cx</b></center></td> 00140 <td><center><b>cy</b></center></td> 00141 </tr> 00142 00143 <tr> 00144 <td><center>0</center></td> 00145 <td><center>Point Grey Research</center></td> 00146 <td><center>Bumblebee</center></td> 00147 <td><center>0.79345</center></td> 00148 <td><center>1.05793</center></td> 00149 <td><center>0.55662</center></td> 00150 <td><center>0.52692</center></td> 00151 </tr> 00152 00153 <tr> 00154 <td><center>1</center></td> 00155 <td><center>Sony</center></td> 00156 <td><center>???</center></td> 00157 <td><center>0.95666094</center></td> 00158 <td><center>1.3983423f</center></td> 00159 <td><center>0.54626328f</center></td> 00160 <td><center>0.4939191f</center></td> 00161 </tr> 00162 </table> 00163 </center> 00164 00165 * \sa buildIntrinsicParamsMatrix, pixelTo3D 00166 */ 00167 CMatrixDouble33 VISION_IMPEXP defaultIntrinsicParamsMatrix( 00168 unsigned int camIndex = 0, 00169 unsigned int resolutionX = 320, 00170 unsigned int resolutionY = 240 ); 00171 00172 /** Explore the feature list and removes features which are in the same coordinates 00173 * \param list (Input). The list of features. 00174 */ 00175 void VISION_IMPEXP deleteRepeatedFeats( CFeatureList &list ); 00176 00177 /** Search for correspondences which are not in the same row and deletes them 00178 * ... 00179 */ 00180 void VISION_IMPEXP rowChecking( CFeatureList &leftList, 00181 CFeatureList &rightList, 00182 float threshold = 0.0); 00183 00184 /** Computes the dispersion of the features in the image 00185 * \param list (IN) Input list of features 00186 * \param std (OUT) 2 element vector containing the standard deviations in the 'x' and 'y' coordinates. 00187 * \param mean (OUT) 2 element vector containing the mean in the 'x' and 'y' coordinates. 00188 */ 00189 void VISION_IMPEXP getDispersion( const CFeatureList &list, 00190 vector_float &std, 00191 vector_float &mean ); 00192 00193 00194 00195 /** Returns a new image where distortion has been removed. 00196 * \param A The 3x3 intrinsic parameters matrix 00197 * \param dist_coeffs The 1x4 (or 1x5) vector of distortion coefficients 00198 */ 00199 inline void correctDistortion( 00200 const CImage &in_img, 00201 CImage &out_img, 00202 const CMatrixDouble33 &A, 00203 const vector_double &dist_coeffs ) 00204 { 00205 in_img.rectifyImage( out_img, A, dist_coeffs); 00206 } 00207 00208 00209 /** Computes the mean squared distance between a set of 3D correspondences 00210 * ... 00211 */ 00212 double VISION_IMPEXP computeMsd( const mrpt::utils::TMatchingPairList &list, 00213 const mrpt::poses::CPose3D &Rt ); 00214 00215 /** Transform two clouds of 3D points into a matched list of points 00216 * ... 00217 */ 00218 void VISION_IMPEXP cloudsToMatchedList( const mrpt::slam::CObservationVisualLandmarks &cloud1, 00219 const mrpt::slam::CObservationVisualLandmarks &cloud2, 00220 mrpt::utils::TMatchingPairList &outList); 00221 00222 /** Computes the main orientation of a set of points with an image (for using in SIFT-based algorithms) 00223 * \param image (Input). The input image. 00224 * \param x (Input). A vector containing the 'x' coordinates of the image points. 00225 * \param y (Input). A vector containing the 'y' coordinates of the image points. 00226 * \param orientation (Output). A vector containing the main orientation of the image points. 00227 */ 00228 float VISION_IMPEXP computeMainOrientation( const CImage &image, 00229 const unsigned int &x, 00230 const unsigned int &y ); 00231 00232 /** Find the matches between two lists of features. They must be of the same type. Return value: the number of matched pairs of features 00233 * \param list1 (Input). One list. 00234 * \param list2 (Input). Other list. 00235 * \param matches (Output). A vector of pairs of correspondences. 00236 * \param options (Optional Input). A struct containing matching options 00237 */ 00238 size_t VISION_IMPEXP matchFeatures( const CFeatureList &list1, 00239 const CFeatureList &list2, 00240 CMatchedFeatureList &matches, 00241 const TMatchingOptions &options = TMatchingOptions() ); 00242 00243 /** Find the matches between two lists of features. They must be of the same type. Return value: the number of matched pairs of features 00244 * \param list1 (Input). One list. 00245 * \param list2 (Input). Other list. 00246 * \param matches (Output). A vector of pairs of correspondences. 00247 * \param options (Optional Input). A struct containing matching options 00248 */ 00249 size_t VISION_IMPEXP matchFeatures2( const CFeatureList &list1, 00250 const CFeatureList &list2, 00251 CMatchedFeatureList &matches, 00252 const TMatchingOptions &options = TMatchingOptions() ); 00253 00254 00255 /** Draw rectangles around each of the features. 00256 */ 00257 void VISION_IMPEXP addFeaturesToImage( 00258 const CImage &inImg, 00259 const CFeatureList &theList, 00260 CImage &outImg ); 00261 00262 /** Project a list of matched features into the 3D space, using the provided options for the stereo system 00263 * \param matches (Input). The list of matched features. 00264 * \param options (Input). The options of the stereo system. 00265 * \param landmarks (Output). A map containing the projected landmarks. 00266 */ 00267 void VISION_IMPEXP projectMatchedFeatures( 00268 CMatchedFeatureList &mfList, // The set of matched features 00269 const vision::TStereoSystemParams ¶m, // Parameters for the stereo system 00270 mrpt::slam::CLandmarksMap &landmarks ); // Output map of 3D landmarks 00271 00272 /** Project a pair of feature lists into the 3D space, using the provided options for the stereo system. The matches must be in order, 00273 * i.e. leftList[0] corresponds to rightList[0] and so on; 00274 * \param leftList (Input). The left list of matched features. 00275 * \param rightList (Input). The right list of matched features. 00276 * \param options (Input). The options of the stereo system. 00277 * \param landmarks (Output). A map containing the projected landmarks. 00278 */ 00279 void VISION_IMPEXP projectMatchedFeatures( 00280 CFeatureList &leftList, // The left of matched features (matches must be ordered!) 00281 CFeatureList &rightList, // The right of matched features (matches must be ordered!) 00282 const vision::TStereoSystemParams ¶m, // Parameters for the stereo system 00283 mrpt::slam::CLandmarksMap &landmarks ); // Output map of 3D landmarks 00284 00285 00286 /** Converts a stereo images observation into a bearing and range observation. 00287 \param inObs [IN] The input stereo images observation. 00288 \param sg [IN] The sigma of the row, col, and disparity variables involved in the feature detection. 00289 \param outObs [OUT] The output bearing and range observation (including covariances). 00290 */ 00291 void VISION_IMPEXP StereoObs2BRObs( 00292 const CObservationStereoImages &inObs, 00293 const std::vector<double> &sg, 00294 CObservationBearingRange &outObs 00295 ); 00296 00297 /** Converts a matched feature list into a bearing and range observation (some of the stereo camera system must be provided). 00298 \param inMatches [IN] The input list of matched features. 00299 \param intrinsicParams [IN] The intrisic params of the reference (left) camera of the stereo system. 00300 \param baseline [IN] The distance among the X axis of the right camera wrt the reference (left) camera. 00301 \param sg [IN] The sigma of the row, col, and disparity variables involved in the feature detection. 00302 \param outObs [OUT] The output bearing and range observation (including covariances). 00303 */ 00304 void VISION_IMPEXP StereoObs2BRObs( 00305 const CMatchedFeatureList &inMatches, 00306 const CMatrixDouble33 &intrinsicParams, 00307 const double &baseline, 00308 const CPose3D &sensorPose, 00309 const std::vector<double> &sg, 00310 CObservationBearingRange &outObs 00311 ); 00312 00313 /** Converts a CObservationVisualLandmarks into a bearing and range observation (without any covariances). Fields of view are not computed. 00314 \param inObs [IN] The input observation. 00315 \param outObs [OUT] The output bearing and range observation. 00316 */ 00317 void VISION_IMPEXP StereoObs2BRObs( 00318 const CObservationVisualLandmarks &inObs, 00319 CObservationBearingRange &outObs 00320 ); 00321 } 00322 } 00323 00324 00325 #endif
| Page generated by Doxygen 1.7.1 for MRPT 0.9.1 SVN:exported at Fri Aug 6 10:31:35 UTC 2010 |
