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