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 #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 #include <mrpt/math/ops_matrices.h> 00035 00036 #include <mrpt/vision/link_pragmas.h> 00037 00038 namespace mrpt 00039 { 00040 namespace vision 00041 { 00042 using namespace mrpt::utils; 00043 using namespace mrpt::math; 00044 00045 class CFeatureList; 00046 class CMatchedFeatureList; 00047 00048 /** Definition of a feature ID 00049 */ 00050 typedef uint64_t TFeatureID; 00051 00052 /** 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 00053 */ 00054 enum TFeatureType 00055 { 00056 featNotDefined = -1, //!< Non-defined feature (also used for Occupancy features) 00057 featKLT = 0, //!< Kanade-Lucas-Tomasi feature [SHI'94] 00058 featHarris, //!< Harris border and corner detector [HARRIS] 00059 featBCD, //!< Binary corder detector 00060 featSIFT, //!< Scale Invariant Feature Transform [LOWE'04] 00061 featSURF, //!< Speeded Up Robust Feature [BAY'06] 00062 featBeacon, //!< A especial case: this is not an image feature, but a 2D/3D beacon (used for range-only SLAM from mrpt::slam::CLandmark) 00063 featFAST //!< FAST feature detector ("Faster and better: A machine learning approach to corner detection", E. Rosten, R. Porter and T. Drummond, PAMI, 2009). 00064 }; 00065 00066 /** The bitwise OR combination of values of TDescriptorType are used in CFeatureExtraction::computeDescriptors to indicate which descriptors are to be computed for features. 00067 */ 00068 enum TDescriptorType 00069 { 00070 descAny = 0, //!< Used in some methods to mean "any of the present descriptors" 00071 descSIFT = 1, //!< SIFT descriptors 00072 descSURF = 2, //!< SURF descriptors 00073 descSpinImages = 4, //!< Intensity-domain spin image descriptors 00074 descPolarImages = 8, //!< Polar image descriptor 00075 descLogPolarImages = 16 //!< Log-Polar image descriptor 00076 }; 00077 00078 enum TKLTFeatureStatus 00079 { 00080 /** Inactive 00081 */ 00082 statusKLT_IDLE, 00083 /** Out Of Bounds 00084 */ 00085 statusKLT_OOB, 00086 /** Determinant of the matrix too small 00087 */ 00088 statusKLT_SMALL_DET, 00089 /** Error too big 00090 */ 00091 statusKLT_LARGE_RESIDUE, 00092 /** 00093 */ 00094 statusKLT_MAX_RESIDUE, 00095 /** Feature correctly tracked 00096 */ 00097 statusKLT_TRACKED, 00098 /** Iteration maximum reached 00099 */ 00100 statusKLT_MAX_ITERATIONS 00101 }; 00102 00103 /**************************************************** 00104 Class CFEATURE 00105 *****************************************************/ 00106 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CFeature, mrpt::utils::CSerializable, VISION_IMPEXP ) 00107 00108 /** A generic 2D feature from an image, extracted with \a CFeatureExtraction 00109 * Each feature may have one or more descriptors (see \a descriptors), in addition to an image patch. 00110 * The (Euclidean) distance between descriptors in a pair of features can be computed with descriptorDistanceTo, 00111 * while the similarity of the patches is given by patchCorrelationTo. 00112 */ 00113 class VISION_IMPEXP CFeature : public mrpt::utils::CSerializable 00114 { 00115 friend class CFeatureList; 00116 friend class CMatchedFeatureList; 00117 00118 DEFINE_SERIALIZABLE( CFeature ) 00119 00120 public: 00121 float x,y; //!< Coordinates in the image 00122 TFeatureID ID; //!< ID of the feature 00123 CImage patch; //!< A patch of the image surrounding the feature 00124 uint16_t patchSize; //!< Size of the patch (patchSize x patchSize) (it must be an odd number) 00125 TFeatureType type; //!< Type of the feature: featNotDefined, featSIFT, featKLT, featHarris, featSURF, featBeacon 00126 TKLTFeatureStatus KLT_status; //!< Status of the feature tracking process 00127 float KLT_val; //!< Value of the goodness of the feature 00128 float orientation; //!< Main orientation of the feature 00129 float scale; //!< Feature scale into the scale space 00130 uint8_t IDSourceImage; //!< ID of the image from which the feature was extracted. 00131 00132 bool isPointFeature() const; //!< Return false only for Blob detectors (SIFT, SURF) 00133 00134 /** All the possible descriptors this feature may have */ 00135 struct VISION_IMPEXP TDescriptors 00136 { 00137 TDescriptors(); // Initialization 00138 00139 std::vector<unsigned char> SIFT; //!< Feature descriptor 00140 std::vector<float> SURF; //!< Feature descriptor 00141 std::vector<float> SpinImg; //!< The 2D histogram as a single row 00142 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. 00143 mrpt::math::CMatrix PolarImg; //!< A polar image centered at the interest point 00144 mrpt::math::CMatrix LogPolarImg; //!< A log-polar image centered at the interest point 00145 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) 00146 00147 bool hasDescriptorSIFT() const { return !SIFT.empty(); }; //!< Whether this feature has this kind of descriptor 00148 bool hasDescriptorSURF() const { return !SURF.empty(); } //!< Whether this feature has this kind of descriptor 00149 bool hasDescriptorSpinImg() const { return !SpinImg.empty(); }; //!< Whether this feature has this kind of descriptor 00150 bool hasDescriptorPolarImg() const { return size(PolarImg,1)>0; } ; //!< Whether this feature has this kind of descriptor 00151 bool hasDescriptorLogPolarImg() const { return size(LogPolarImg,1)>0; } ; //!< Whether this feature has this kind of descriptor 00152 } 00153 descriptors; 00154 00155 /** Return the first found descriptor, as a matrix. 00156 * \return false on error, i.e. there is no valid descriptor. 00157 */ 00158 bool getFirstDescriptorAsMatrix(mrpt::math::CMatrixFloat &desc) const; 00159 00160 /** 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). 00161 * \note If this or the other features does not have patches or they are of different sizes, an exception will be raised. 00162 * \sa descriptorDistanceTo 00163 */ 00164 float patchCorrelationTo( const CFeature &oFeature) const; 00165 00166 /** Computes the Euclidean Distance between this feature's and other feature's descriptors, using the given descriptor or the first present one. 00167 * \note If descriptorToUse is not descAny and that descriptor is not present in one of the features, an exception will be raised. 00168 * \sa patchCorrelationTo 00169 */ 00170 float descriptorDistanceTo( const CFeature &oFeature, TDescriptorType descriptorToUse = descAny, bool normalize_distances = true ) const; 00171 00172 /** Computes the Euclidean Distance between "this" and the "other" descriptors */ 00173 float descriptorSIFTDistanceTo( const CFeature &oFeature, bool normalize_distances = true ) const; 00174 00175 /** Computes the Euclidean Distance between "this" and the "other" descriptors */ 00176 float descriptorSURFDistanceTo( const CFeature &oFeature, bool normalize_distances = true ) const; 00177 00178 /** Computes the Euclidean Distance between "this" and the "other" descriptors */ 00179 float descriptorSpinImgDistanceTo( const CFeature &oFeature, bool normalize_distances = true ) const; 00180 00181 /** Returns the minimum Euclidean Distance between "this" and the "other" polar image descriptor, for the best shift in orientation. 00182 * \param oFeature The other feature to compare with. 00183 * \param minDistAngle The placeholder for the angle at which the smallest distance is found. 00184 * \return The distance for the best orientation (minimum distance). 00185 */ 00186 float descriptorPolarImgDistanceTo( 00187 const CFeature &oFeature, 00188 float &minDistAngle, 00189 bool normalize_distances = true ) const; 00190 00191 /** Returns the minimum Euclidean Distance between "this" and the "other" log-polar image descriptor, for the best shift in orientation. 00192 * \param oFeature The other feature to compare with. 00193 * \param minDistAngle The placeholder for the angle at which the smallest distance is found. 00194 * \return The distance for the best orientation (minimum distance). 00195 */ 00196 float descriptorLogPolarImgDistanceTo( 00197 const CFeature &oFeature, 00198 float &minDistAngle, 00199 bool normalize_distances = true ) const; 00200 00201 /** Get the type of the feature 00202 */ 00203 TFeatureType get_type() const { return type; } 00204 00205 /** Constructor 00206 */ 00207 CFeature(); 00208 00209 /** Virtual destructor */ 00210 virtual ~CFeature() {} 00211 00212 00213 protected: 00214 //unsigned int numRefs; 00215 00216 /** Internal function used by "descriptorLogPolarImgDistanceTo" and "descriptorPolarImgDistanceTo" 00217 */ 00218 static float internal_distanceBetweenPolarImages( 00219 const mrpt::math::CMatrix &desc1, 00220 const mrpt::math::CMatrix &desc2, 00221 float &minDistAngle, 00222 bool normalize_distances, 00223 bool dont_shift_angle ); 00224 00225 }; // end of class 00226 00227 /**************************************************** 00228 Class CFEATURELIST 00229 *****************************************************/ 00230 /** A list of features 00231 */ 00232 class VISION_IMPEXP CFeatureList : public std::deque<CFeaturePtr> 00233 { 00234 public: 00235 00236 /** The type of feature which contains 00237 */ 00238 TFeatureType get_type() const { 00239 if( size() > 0 ) 00240 return (*begin())->get_type(); 00241 else 00242 return featNotDefined; 00243 } 00244 00245 /** Save feature list to a text file 00246 */ 00247 void saveToTextFile( const std::string &fileName, bool APPEND = false ); 00248 00249 /** Save feature list to a text file 00250 */ 00251 void loadFromTextFile( const std::string &fileName ); 00252 00253 /** Get the maximum ID into the list 00254 */ 00255 TFeatureID getMaxID() const; 00256 00257 /** Get a reference to a Feature from its ID 00258 */ 00259 CFeaturePtr getByID( TFeatureID ID ) const; 00260 00261 /** Get a reference of the nearest Feature to a given point 00262 * Use dist_prev to stablish the maximum distance of search, this parameter gives the distance of the nearest element 00263 */ 00264 CFeaturePtr nearest( const double &x, const double &y, double &dist_prev ) const; 00265 00266 /** Constructor 00267 */ 00268 CFeatureList(); 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 VISION_IMPEXP 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 /** Constructor 00297 */ 00298 CMatchedFeatureList(); 00299 00300 /** Virtual destructor */ 00301 virtual ~CMatchedFeatureList(); 00302 }; // end of class 00303 00304 } // end of namespace 00305 00306 namespace utils 00307 { 00308 using namespace ::mrpt::vision; 00309 // Specialization must occur in the same namespace 00310 MRPT_DECLARE_TTYPENAME_PTR(CFeature) 00311 } 00312 00313 00314 } // end of namespace 00315 00316 #endif 00317
| Page generated by Doxygen 1.6.1 for MRPT 0.9.0 SVN: at Mon Jun 7 06:47:58 UTC 2010 |
