GSoC2011SfM  0.1
Google Summer of Code 2011: Structure from motion
D:/Travail/These/Determination caracteristiques camera/GSoC/SfM/src/PointsToTrack.h
00001 #ifndef _GSOC_SFM_POINTS_TO_TRACK_H
00002 #define _GSOC_SFM_POINTS_TO_TRACK_H 1
00003 
00004 #include "macro.h" //SFM_EXPORTS and remove annoying warnings
00005 
00006 #include <vector>
00007 #include "opencv2/features2d/features2d.hpp"
00008 
00009 #include "config_SFM.h"//semaphore...
00010 
00011 
00012 namespace OpencvSfM{
00013   class SFM_EXPORTS TrackOfPoints;
00014 
00025   class SFM_EXPORTS PointsToTrack
00026   {
00027   protected:
00033     DECLARE_MUTEX(worker_exclusion);
00038     unsigned int nb_workers_;
00043     std::vector<cv::KeyPoint> keypoints_;
00049     cv::Mat descriptors_;
00050 
00054     cv::Mat imageToAnalyse_;
00058     std::vector<unsigned int> RGB_values_;
00059     int corresponding_image_;
00060     static int glob_number_images_;
00061 
00067     virtual int impl_computeKeypoints_( ){return 0;};
00072     virtual void impl_computeDescriptors_( ){};
00078     void impl_filterByDistance_( double dist_min );
00079     
00080   public:
00087     PointsToTrack( int corresponding_image=-1, std::vector<cv::KeyPoint> keypoints=
00088       std::vector<cv::KeyPoint>( 0 ), cv::Mat descriptors=cv::Mat( ) );
00092     virtual ~PointsToTrack( void );
00097     void free_descriptors( bool force = false );
00098 
00105     int computeKeypointsAndDesc( bool forcing_recalculation=false );
00110     int computeKeypoints( );
00114     void computeDescriptors( );
00121     void addKeypoints( std::vector<cv::KeyPoint> keypoints,cv::Mat descriptors=cv::Mat( ),bool computeMissingDescriptor=false );
00130     inline unsigned int addKeypoint( const cv::KeyPoint point, double min_dist=1.0 )
00131     {
00132       double dist = 1e6;
00133       P_MUTEX(worker_exclusion);
00134       size_t nb_points = keypoints_.size(),
00135         close_p = 0;
00136       float dist_min = 1e10;
00137       for(size_t i = 0; i<nb_points ; ++i)
00138       {
00139         const cv::KeyPoint& kp = keypoints_[i];
00140         float dist = sqrt( (point.pt.x - kp.pt.x)*(point.pt.x - kp.pt.x)
00141           + (point.pt.y - kp.pt.y) * (point.pt.y - kp.pt.y) );
00142         if( dist<dist_min )
00143         {
00144           dist_min = dist;
00145           close_p = i;
00146         }
00147       }
00148       if( dist_min > min_dist )
00149       {
00150         keypoints_.push_back( point );
00151         close_p = keypoints_.size() - 1;
00152       }
00153       V_MUTEX(worker_exclusion);
00154       return close_p;
00155     };
00160     inline std::vector<cv::KeyPoint>& getModifiableKeypoints( ) {return keypoints_;};
00165     inline const std::vector<cv::KeyPoint>& getKeypoints( ) const {return keypoints_;};
00173     void getKeyMatches( const std::vector<TrackOfPoints>& matches, int otherImage,
00174       std::vector<cv::Point2f>& pointsVals ) const;
00180     inline const cv::KeyPoint& getKeypoint( unsigned int index ) const
00181     {
00182       //CV_DbgAssert( index<keypoints_.size( ) );
00183       return keypoints_[ index ];
00184     };
00190     size_t getClosestKeypoint( cv::Point2f point );
00195     cv::Mat getDescriptors( ) const {return descriptors_;};
00199     inline cv::Mat getImage( ){return imageToAnalyse_;};
00207     //
00208     void printPointsOnImage( const cv::Mat &image, cv::Mat& outImg, const cv::Scalar& color=cv::Scalar::all( -1 ), int flags=cv::DrawMatchesFlags::DEFAULT ) const;
00209 
00215     inline unsigned int getColor( unsigned int index ) const{
00216       if( index<RGB_values_.size() )
00217         return RGB_values_[index];
00218       else
00219         return 0;
00220     }
00221     
00226     void filterByDistance( double dist_min );
00227 
00233     static void read( const cv::FileNode& node, PointsToTrack& points );
00234 
00240     static void write( cv::FileStorage& fs, const PointsToTrack& points );
00241   };
00242 }
00243 /*
00245 static inline void cv::write( cv::FileStorage& fs, const std::string& name,
00246   const OpencvSfM::PointsToTrack& points )
00247 {
00248   OpencvSfM::PointsToTrack::write( fs,points );
00249 };
00251 static inline void cv::read( const cv::FileNode& node, OpencvSfM::PointsToTrack& points,
00252   OpencvSfM::PointsToTrack defaultValue = OpencvSfM::PointsToTrack( ) )
00253 {
00254   OpencvSfM::PointsToTrack::read( node,points );
00255 }
00256 */
00257 #endif
 All Classes Functions Variables