00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 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 #ifndef CFeature_H 00029 #define CFeature_H 00030 00031 #include <mrpt/utils/CImage.h> 00032 #include <mrpt/utils/stl_extensions.h> 00033 #include <mrpt/math/CMatrix.h> 00034 00035 namespace mrpt 00036 { 00037 namespace vision 00038 { 00039 using namespace mrpt::utils; 00040 00041 class MRPTDLLIMPEXP CFeatureList; 00042 class MRPTDLLIMPEXP CMatchedFeatureList; 00043 00044 /** Definition of a feature ID 00045 */ 00046 typedef uint64_t TFeatureID; 00047 00048 /** Types of features - This means that the point has been detected with this algorithm, which is independent of additional descriptors a feature may also have 00049 */ 00050 enum TFeatureType 00051 { 00052 featNotDefined = -1, //!< Non-defined feature (also used for Occupancy features) 00053 featKLT = 0, //!< Kanade-Lucas-Tomasi feature [SHI'94] 00054 featHarris, //!< Harris border and corner detector [HARRIS] 00055 featBCD, //!< Binary corder detector 00056 featSIFT, //!< Scale Invariant Feature Transform [LOWE'04] 00057 featSURF, //!< Speeded Up Robust Feature [BAY'06] 00058 featBeacon //!< A especial case: this is not an image feature, but a 2D/3D beacon (used for range-only SLAM from mrpt::slam::CLandmark) 00059 }; 00060 00061 /** The bitwise OR combination of values of TDescriptorType are used in CFeatureExtraction::computeDescriptors to indicate which descriptors are to be computed for features. 00062 */ 00063 enum TDescriptorType 00064 { 00065 descAny = 0, //!< Used in some methods to mean "any of the present descriptors" 00066 descSIFT = 1, //!< SIFT descriptors 00067 descSURF = 2, //!< SURF descriptors 00068 descSpinImages = 4, //!< Intensity-domain spin image descriptors 00069 descPolarImages = 8, //!< Polar image descriptor 00070 descLogPolarImages = 16 //!< Log-Polar image descriptor 00071 }; 00072 00073 enum TKLTFeatureStatus 00074 { 00075 /** Inactive 00076 */ 00077 statusKLT_IDLE, 00078 /** Out Of Bounds 00079 */ 00080 statusKLT_OOB, 00081 /** Determinant of the matrix too small 00082 */ 00083 statusKLT_SMALL_DET, 00084 /** Error too big 00085 */ 00086 statusKLT_LARGE_RESIDUE, 00087 /** 00088 */ 00089 statusKLT_MAX_RESIDUE, 00090 /** Feature correctly tracked 00091 */ 00092 statusKLT_TRACKED, 00093 /** Iteration maximum reached 00094 */ 00095 statusKLT_MAX_ITERATIONS 00096 }; 00097 00098 /**************************************************** 00099 Class CFEATURE 00100 *****************************************************/ 00101 DEFINE_SERIALIZABLE_PRE( CFeature ) 00102 00103 /** A generic 2D feature from an image, extracted with \a CFeatureExtraction 00104 * Each feature may have one or more descriptors (see \a descriptors), in addition to an image patch. 00105 * The (Euclidean) distance between descriptors in a pair of features can be computed with descriptorDistanceTo, 00106 * while the similarity of the patches is given by patchCorrelationTo. 00107 */ 00108 class MRPTDLLIMPEXP CFeature : public mrpt::utils::CSerializable 00109 { 00110 friend class CFeatureList; 00111 friend class CMatchedFeatureList; 00112 00113 DEFINE_SERIALIZABLE( CFeature ) 00114 00115 public: 00116 float x,y; //!< Coordinates in the image 00117 TFeatureID ID; //!< ID of the feature 00118 CImage patch; //!< A patch of the image surrounding the feature 00119 uint16_t patchSize; //!< Size of the patch (patchSize x patchSize) (it must be an odd number) 00120 TFeatureType type; //!< Type of the feature: featNotDefined, featSIFT, featKLT, featHarris, featSURF, featBeacon 00121 TKLTFeatureStatus KLT_status; //!< Status of the feature tracking process 00122 float KLT_val; //!< Value of the goodness of the feature 00123 float orientation; //!< Main orientation of the feature 00124 float scale; //!< Feature scale into the scale space 00125 uint8_t IDSourceImage; //!< ID of the image from which the feature was extracted. 00126 00127 /** All the possible descriptors this feature may have */ 00128 struct MRPTDLLIMPEXP TDescriptors 00129 { 00130 TDescriptors(); // Initialization 00131 00132 std::vector<unsigned char> SIFT; //!< Feature descriptor 00133 std::vector<float> SURF; //!< Feature descriptor 00134 std::vector<float> SpinImg; //!< The 2D histogram as a single row 00135 uint16_t SpinImg_range_rows; //!< The number of rows (corresponding to range bins in the 2D histogram) of the original matrix from which SpinImg was extracted as a vector. 00136 mrpt::math::CMatrix PolarImg; //!< A polar image centered at the interest point 00137 mrpt::math::CMatrix LogPolarImg; //!< A log-polar image centered at the interest point 00138 bool polarImgsNoRotation; //!< If set to true (manually, default=false) the call to "descriptorDistanceTo" will not consider all the rotations between polar image descriptors (PolarImg, LogPolarImg) 00139 00140 bool hasDescriptorSIFT() const { return !SIFT.empty(); }; //!< Whether this feature has this kind of descriptor 00141 bool hasDescriptorSURF() const { return !SURF.empty(); } //!< Whether this feature has this kind of descriptor 00142 bool hasDescriptorSpinImg() const { return !SpinImg.empty(); }; //!< Whether this feature has this kind of descriptor 00143 bool hasDescriptorPolarImg() const { return size(PolarImg,1)>0; } ; //!< Whether this feature has this kind of descriptor 00144 bool hasDescriptorLogPolarImg() const { return size(LogPolarImg,1)>0; } ; //!< Whether this feature has this kind of descriptor 00145 } 00146 descriptors; 00147 00148 /** Return the first found descriptor, as a matrix. 00149 * \return false on error, i.e. there is no valid descriptor. 00150 */ 00151 bool getFirstDescriptorAsMatrix(mrpt::math::CMatrixFloat &desc) const; 00152 00153 /** Computes the normalized cross-correlation between the patches of this and another feature (normalized in the range [0,1], such as 0=best, 1=worst). 00154 * \note If this or the other features does not have patches or they are of different sizes, an exception will be raised. 00155 * \sa descriptorDistanceTo 00156 */ 00157 float patchCorrelationTo( const CFeature &oFeature) const; 00158 00159 /** Computes the Euclidean Distance between this feature's and other feature's descriptors, using the given descriptor or the first present one. 00160 * \note If descriptorToUse is not descAny and that descriptor is not present in one of the features, an exception will be raised. 00161 * \sa patchCorrelationTo 00162 */ 00163 float descriptorDistanceTo( const CFeature &oFeature, TDescriptorType descriptorToUse = descAny, bool normalize_distances = true ) const; 00164 00165 /** Computes the Euclidean Distance between "this" and the "other" descriptors */ 00166 float descriptorSIFTDistanceTo( const CFeature &oFeature, bool normalize_distances = true ) const; 00167 00168 /** Computes the Euclidean Distance between "this" and the "other" descriptors */ 00169 float descriptorSURFDistanceTo( const CFeature &oFeature, bool normalize_distances = true ) const; 00170 00171 /** Computes the Euclidean Distance between "this" and the "other" descriptors */ 00172 float descriptorSpinImgDistanceTo( const CFeature &oFeature, bool normalize_distances = true ) const; 00173 00174 /** Returns the minimum Euclidean Distance between "this" and the "other" polar image descriptor, for the best shift in orientation. 00175 * \param oFeature The other feature to compare with. 00176 * \param minDistAngle The placeholder for the angle at which the smallest distance is found. 00177 * \return The distance for the best orientation (minimum distance). 00178 */ 00179 float descriptorPolarImgDistanceTo( 00180 const CFeature &oFeature, 00181 float &minDistAngle, 00182 bool normalize_distances = true ) const; 00183 00184 /** Returns the minimum Euclidean Distance between "this" and the "other" log-polar image descriptor, for the best shift in orientation. 00185 * \param oFeature The other feature to compare with. 00186 * \param minDistAngle The placeholder for the angle at which the smallest distance is found. 00187 * \return The distance for the best orientation (minimum distance). 00188 */ 00189 float descriptorLogPolarImgDistanceTo( 00190 const CFeature &oFeature, 00191 float &minDistAngle, 00192 bool normalize_distances = true ) const; 00193 00194 /** Get the type of the feature 00195 */ 00196 TFeatureType get_type() const { return type; } 00197 00198 /** Constructor 00199 */ 00200 CFeature(); 00201 00202 /** Virtual destructor */ 00203 virtual ~CFeature() {} 00204 00205 00206 protected: 00207 //unsigned int numRefs; 00208 00209 /** Internal function used by "descriptorLogPolarImgDistanceTo" and "descriptorPolarImgDistanceTo" 00210 */ 00211 static float internal_distanceBetweenPolarImages( 00212 const mrpt::math::CMatrix &desc1, 00213 const mrpt::math::CMatrix &desc2, 00214 float &minDistAngle, 00215 bool normalize_distances, 00216 bool dont_shift_angle ); 00217 00218 }; // end of class 00219 00220 /**************************************************** 00221 Class CFEATURELIST 00222 *****************************************************/ 00223 /** A list of features 00224 */ 00225 class MRPTDLLIMPEXP CFeatureList : public std::deque<CFeaturePtr> 00226 { 00227 public: 00228 00229 /** The type of feature which contains 00230 */ 00231 TFeatureType get_type() const { 00232 if( size() > 0 ) 00233 return (*begin())->get_type(); 00234 else 00235 return featNotDefined; 00236 } 00237 00238 /** Save feature list to a text file 00239 */ 00240 void saveToTextFile( const std::string &fileName, bool APPEND = false ); 00241 00242 /** Save feature list to a text file 00243 */ 00244 TFeatureID getMaxID(); 00245 00246 /** Get a reference to a Feature from its ID 00247 */ 00248 CFeaturePtr getByID( TFeatureID ID ) const; 00249 00250 /** Insert a feature into the list (use this function instead of push_back) 00251 */ 00252 void insert( const CFeaturePtr &feat ); 00253 00254 /** Remove a feature from the list (use this function instead of erase) 00255 */ 00256 CFeatureList::iterator remove( CFeatureList::iterator itFeat ); 00257 00258 /** Constructor 00259 */ 00260 CFeatureList(); 00261 00262 /** Copy Constructor 00263 */ 00264 CFeatureList(const CFeatureList &o); 00265 00266 /** Copy Operator 00267 */ 00268 CFeatureList& operator=(const CFeatureList &o); 00269 00270 /** Virtual destructor */ 00271 virtual ~CFeatureList(); 00272 00273 }; // end of class 00274 00275 /**************************************************** 00276 Class CMATCHEDFEATURELIST 00277 *****************************************************/ 00278 /** A list of features 00279 */ 00280 class MRPTDLLIMPEXP CMatchedFeatureList : public std::deque< std::pair<CFeaturePtr,CFeaturePtr> > 00281 { 00282 public: 00283 /** The type of feature which contains 00284 */ 00285 TFeatureType get_type() const { 00286 if( size() > 0 ) 00287 return (begin()->first)->get_type(); 00288 else 00289 return featNotDefined; 00290 } 00291 00292 /** Save list of matched features to a text file 00293 */ 00294 void saveToTextFile(const std::string &fileName); 00295 00296 /** Insert a pair of matched features into the list (use this function instead of push_back) 00297 */ 00298 void insert( const std::pair<CFeaturePtr,CFeaturePtr> &mFeats ); 00299 00300 /** Remove a pair of matched features from the list (use this function instead of erase) 00301 */ 00302 CMatchedFeatureList::iterator remove( CMatchedFeatureList::iterator pMatchedFeats ); 00303 00304 /** Constructor 00305 */ 00306 CMatchedFeatureList(); 00307 00308 /** Copy Constructor 00309 */ 00310 CMatchedFeatureList(const CMatchedFeatureList &o); 00311 00312 /** Copy Operator 00313 */ 00314 CMatchedFeatureList& operator=(const CMatchedFeatureList &o); 00315 00316 /** Virtual destructor */ 00317 virtual ~CMatchedFeatureList(); 00318 }; // end of class 00319 00320 } // end of namespace 00321 00322 namespace utils 00323 { 00324 using namespace ::mrpt::vision; 00325 // Specialization must occur in the same namespace 00326 MRPT_DECLARE_TTYPENAME_PTR(CFeature) 00327 } 00328 00329 00330 } // end of namespace 00331 00332 #endif 00333
Page generated by Doxygen 1.5.9 for MRPT 0.7.1 SVN: at Mon Aug 17 22:20:53 EDT 2009 |