Main MRPT website > C++ reference
MRPT logo

multiDesc_utils.h

Go to the documentation of this file.
00001             /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  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_multiDesc_utils_H
00030 #define mrpt_multiDesc_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 vision
00051     {
00052                 using namespace std;
00053                 using namespace mrpt::slam;
00054                 using namespace mrpt::math;
00055                 using namespace mrpt::utils;
00056 
00057         // A 3D quantization table for storing pairs of TFeatureIDs and scales
00058         typedef map<int,map<int,map<int,deque<pair<TFeatureID, double> > > > > TQuantizationTable;
00059 
00060         void VISION_IMPEXP insertHashCoeffs(
00061                                 const CFeaturePtr                   & feat,
00062                                 TQuantizationTable                  & qTable );
00063 
00064         TMultiResMatchingOutput VISION_IMPEXP relocalizeMultiDesc(
00065                                 const CImage                        & image,
00066                                 CFeatureList                        & baseList,
00067                                 CFeatureList                        & currentList,
00068                                 TQuantizationTable                  & qTable,
00069                                 const TMultiResDescOptions          & desc_opts,
00070                                 const TMultiResDescMatchOptions     & match_opts );
00071 
00072         void VISION_IMPEXP updateBaseList(
00073                                 CFeatureList                        & baseList,
00074                                 const CFeatureList                  & currentList,
00075                                 const vector<int>                   & idx );
00076 
00077         void VISION_IMPEXP checkScalesAndFindMore(
00078                                 CMatchedFeatureList                 & baseList,
00079                                 const CFeatureList                  & currentList,
00080                                 const CImage                        & currentImage,
00081                                 const TMultiResMatchingOutput       & output,
00082                                 const TMultiResDescOptions          & computeOpts,
00083                                 const TMultiResDescMatchOptions     & matchOpts );
00084 
00085         /** Computes the gradient of certain pixel within the image.
00086           * \param image    [IN]    The input image.
00087           * \param x        [IN]    The 'x' coordinate of the image point.
00088           * \param y        [IN]    The 'y' coordinate of the image point.
00089           * \param mag      [OUT]   The magnitude of the gradient.
00090           * \param ori      [OUT]   The orientation of the gradient.
00091           * \return True if the gradient could be computed and False if the pixel is located outside the image or at its border (where the gradient cannot be computed)
00092           */
00093         bool VISION_IMPEXP computeGradient(
00094                                 const CImage                        & image,
00095                                 const unsigned int                  x,
00096                                 const unsigned int                  y,
00097                                 double                              & mag,
00098                                 double                              & ori );
00099 
00100         /** Computes the main orientations (within 80% of the peak value of orientation histogram) of a certain point within an image (for using in SIFT-based algorithms)
00101           * \param image        [IN]    The input image.
00102           * \param x            [IN]    The 'x' coordinate of the image point.
00103           * \param y            [IN]    The 'y' coordinate of the image point.
00104           * \param patchSize    [IN]    The size of the patch to be considered for computing the orientation histogram.
00105           * \param orientations [OUT]   A vector containing the main orientations of the image point.
00106           * \param sigma        [IN]    The sigma value of the Gaussian kernel used to smooth the orientation histogram (typically 7.5 px).
00107           */
00108         bool VISION_IMPEXP computeMainOrientations(
00109                                 const CImage                        & image,
00110                                 const unsigned int                  x,
00111                                 const unsigned int                  y,
00112                                 const unsigned int                  patchSize,
00113                                 std::vector<double>                 & orientations,
00114                                 const double                        & sigma );
00115 
00116         /** Inserts the orientation value of a certain pixel within the keypoint neighbourhood into the histogram of orientations. This value can
00117           * affect to more than one entry within the histogram.
00118           * \param hist [IN/OUT]    The histogram of orientations.
00119           * \param cbin [IN]        The entry rotated column bin.
00120           * \param rbin [IN]        The entry rotated row bin.
00121           * \param obin [IN]        The entry rotated orientation bin.
00122           * \param mag  [IN]        The gradient magnitude value in the pixel.
00123           * \param d    [IN]        The number of row (and column) bins used in the histogram (typically 4).
00124           * \param n    [IN]        The number of orienation bins used in the histogram (typically 8).
00125           */
00126         void VISION_IMPEXP interpolateHistEntry(
00127                                 vector<double>                      & hist,
00128                                 const double                        & cbin,
00129                                 const double                        & rbin,
00130                                 const double                        & obin,
00131                                 const double                        & mag,
00132                                 const int                           d,
00133                                 const int                           n );
00134 
00135         /** Computes the SIFT-like descriptor of a certain point within an image at the base scale, i.e. its rotated orientation histogram.
00136           * \param image        [IN]    The input image.
00137           * \param x            [IN]    The 'x' coordinate of the image point.
00138           * \param y            [IN]    The 'y' coordinate of the image point.
00139           * \param patchSize    [IN]    The size of the patch to be considered for computing the orientation histogram.
00140           * \param orientation  [IN]    The orientation considered for this point (used to rotate the patch).
00141           * \param orientation  [OUT]   The computed SIFT-like descriptor.
00142           * \param opts         [IN]    The options for computing the SIFT-like descriptor.
00143           * \param hashCoeffs   [OUT]   A vector containing the computed coefficients for the HASH table used in relocalization.
00144           * \sa TMultiResDescOptions
00145           */
00146         void VISION_IMPEXP computeHistogramOfOrientations(
00147                                     const CImage                    & image,
00148                                     const unsigned int              x,
00149                                     const unsigned int              y,
00150                                     const unsigned int              patchSize,
00151                                     const double                    & orientation,
00152                                     vector<int32_t>                     & descriptor,
00153                                     const TMultiResDescOptions      & opts,
00154                                     vector<int32_t>                     & hashCoeffs );
00155 
00156         /** Matches two CFeatureList containing mulit-resolution descriptors. The first list is taken as a base, i.e. its features must contain multi-resolution descriptors
00157           * at a set of different scales. The second list doesn't need to contain such information because it will be computed if necessary according to the
00158           * the fulfillment of some restriction regarding the matching process. This function will try to find the best matches within list2 corresponding to the features
00159           * within base list list1.
00160           * \param list1            [IN]        The base list of features.
00161           * \param list2            [IN/OUT]    The other list of features.
00162           * \param rightImage       [IN]        The image from where the list2 was extracted. It's used to compute the descriptor of these features if necessary.
00163           * \param output           [OUT]       The output structure with the matching information.
00164           * \param matchOpts        [IN]        The options structure for the matching process.
00165           * \param computeOpts      [IN]        The options structure for the descriptor computation process.
00166           * \return A structure containing the results of the matching.
00167           * \sa TMultiResDescMatchOptions, TMultiResDescOptions, TMultiResMatchingOutput
00168           */
00169         TMultiResMatchingOutput VISION_IMPEXP matchMultiResolutionFeatures(
00170                                     const CFeatureList              & list1,
00171                                     CFeatureList                    & list2,
00172                                     const CImage                    & rightImage,
00173                                     const TMultiResDescMatchOptions & matchOpts,
00174                                     const TMultiResDescOptions      & computeOpts );
00175 
00176         /** Matches two CMatchedFeatureList containing mulit-resolution descriptors. This is performed for both the "left" and "right" lists
00177           * The first matched list is taken as a base, i.e. its features must contain multi-resolution descriptors
00178           * at a set of different scales. The second list doesn't need to contain such information because it will be computed if necessary according to the
00179           * the fulfillment of some restriction regarding the matching process. This function will try to find the best matches within list2 corresponding to the features
00180           * \param mList1           [IN]    The base list.
00181           * \param mList2           [IN]    The other list of features.
00182           * \param leftImage        [IN]    The image from where the list2 was extracted. It's used to compute the descriptor of these features if necessary.
00183           * \param rightImage       [IN]    The image from where the list2 was extracted. It's used to compute the descriptor of these features if necessary.
00184           * \param matchOpts        [IN]        The options structure for the matching process.
00185           * \param computeOpts      [IN]        The options structure for the descriptor computation process.
00186           * \return The number of matches found
00187           * \sa TMultiResDescMatchOptions
00188           */
00189         int VISION_IMPEXP matchMultiResolutionFeatures(
00190                                     CMatchedFeatureList             & mList1,
00191                                     CMatchedFeatureList             & mList2,
00192                                     const CImage                    & leftImage,
00193                                     const CImage                    & rightImage,
00194                                     const TMultiResDescMatchOptions & matchOpts,
00195                                     const TMultiResDescOptions      & computeOpts );
00196 
00197         /** Computes more multi-resolution SIFT-like descriptors for a feature using its position in a new image. This
00198           * is called when we have found a match between a feature and itself in a new frame but it has been found in
00199           * a boundary scale. We now expand the range of scales, orientations and descriptors for that feature.
00200           * \param image        [IN]    The new frame.
00201           * \param inputFeat    [IN]    The feature in the new frame.
00202           * \param outputFeat   [OUT]   The base feature (detected in the base frame).
00203           * \param lowerScales  [IN]    If we should find descriptors for lower scales or for higher ones.
00204           * \param opts         [IN]    The options for computing the new descriptors.
00205           */
00206         int VISION_IMPEXP computeMoreDescriptors(
00207                                     const CImage                    & image,
00208                                     const CFeaturePtr               & inputFeat,
00209                                     CFeaturePtr                     & outputFeat,
00210                                     const bool                      & lowerScales,
00211                                     const TMultiResDescOptions      & opts );
00212 
00213         /** Computes the initial and final scales where to look when finding a match between multi-resolution features.
00214           * Both features must have their "depth" member properly computed.
00215           * \param feat1        [IN]    The base feature which MUST contain a set of different scales.
00216           * \param feat2        [IN]    The other feature which must be computed at base scale (1.0).
00217           * \param firstScale   [OUT]   The initial scale (within [0 feat1->multiScale.size()-1]) where to look.
00218           * \param firstScale   [OUT]   The final scale (within [0 feat1->multiScale.size()-1]) where to look.
00219           */
00220         void VISION_IMPEXP setProperScales(
00221                                     const CFeaturePtr               & feat1,
00222                                     const CFeaturePtr               & feat2,
00223                                     int                             & firstScale,
00224                                     int                             & lastScale );
00225 
00226         /** Computes the multi-resolution SIFT-like descriptor of a set of matched features
00227           * \param imageLeft    [IN]        The input left image.
00228           * \param imageRight   [IN]        The input right image.
00229           * \param matchedFeats [IN/OUT]    The list of matched features. They will be updated with the multi-scales, multi-orientations, multi-descriptors and depth information.
00230           * \param opts         [IN]        The options structure for the descriptor computation process.
00231           * \sa TMultiResDescOptions
00232         */
00233         void VISION_IMPEXP computeMultiResolutionDescriptors(
00234                                     const CImage                    & imageLeft,
00235                                     const CImage                    & imageRight,
00236                                     CMatchedFeatureList             & matchedFeats,
00237                                     const TMultiResDescOptions      & opts );
00238 
00239 
00240         /** Computes the multi-resolution SIFT-like descriptor of a features
00241           * \param image        [IN]        The input left image.
00242           * \param feat         [IN/OUT]    The feature. It will be updated with the multi-scales, multi-orientations, multi-descriptors
00243           * \param opts         [IN]        The options structure for the descriptor computation process.
00244           * \sa TMultiResDescOptions
00245         */
00246         bool VISION_IMPEXP computeMultiResolutionDescriptors(
00247                                     const CImage                    & image,
00248                                     CFeaturePtr                     & feat,
00249                                     const TMultiResDescOptions      & opts );
00250 
00251         /** Computes the multi-resolution SIFT-like descriptor of a list of features
00252           * \param image    [IN]        The input image.
00253           * \param list     [IN/OUT]    The list of features. They will be updated with the multi-scales, multi-orientations and multi-descriptors information.
00254           * \param opts     [IN]        The options structure for the descriptor computation process.
00255           * \sa TMultiResDescOptions
00256           */
00257         vector<bool> VISION_IMPEXP computeMultiResolutionDescriptors(
00258                                     const CImage                    & image,
00259                                     CFeatureList                    & list,
00260                                     const TMultiResDescOptions      & opts );
00261 
00262         /** Computes the multi-resolution SIFT-like descriptor of a list of features
00263           * \param image    [IN]        The input image.
00264           * \param list     [IN/OUT]    The list of features. They will be updated with the multi-scales, multi-orientations and multi-descriptors information.
00265           * \param opts     [IN]        The options structure for the descriptor computation process.
00266           * \sa TMultiResDescOptions
00267           */
00268         void VISION_IMPEXP computeMultiOrientations(
00269                                     const CImage                    & image,
00270                                     CFeatureList                    & list,
00271                                     const TMultiResDescOptions      & opts );
00272 
00273 
00274 
00275 
00276 
00277 
00278 
00279 
00280 
00281     }
00282 } // end-namespace-mrpt
00283 
00284 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011