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