GSoC2011SfM  0.1
Google Summer of Code 2011: Structure from motion
D:/Travail/These/Determination caracteristiques camera/GSoC/SfM/src/SequenceAnalyzer.h
00001 #ifndef _GSOC_SFM_SEQUENCE_ANALYZER_H
00002 #define _GSOC_SFM_SEQUENCE_ANALYZER_H 1
00003 
00004 #include "macro.h" //SFM_EXPORTS
00005 #include "PointsToTrackWithImage.h"
00006 #include "MotionProcessor.h"
00007 #include "PointsMatcher.h"
00008 #include "PointOfView.h"
00009 //#include "libmv_mapping.h"
00010 #include "TracksOfPoints.h"
00011 #include "opencv2/calib3d/calib3d.hpp"
00012 
00013 namespace OpencvSfM{
00014   struct MatchingThread;
00015 
00025   class SFM_EXPORTS SequenceAnalyzer
00026   {
00027     friend struct MatchingThread;
00028   protected:
00029     static int mininum_points_matches;
00030     static int mininum_image_matches;
00031 
00034     cv::Ptr<cv::FeatureDetector> feature_detector_;
00038     cv::Ptr<cv::DescriptorExtractor> descriptor_extractor_;
00042     std::vector< cv::Ptr< PointsToTrack > > points_to_track_;
00046     std::vector<cv::Mat> images_;
00050     cv::Ptr<PointsMatcher> match_algorithm_;
00055     std::vector< cv::Ptr< PointsMatcher > > matches_;
00060     std::vector<TrackOfPoints> tracks_;
00065     ImagesGraphConnection images_graph_;
00072     std::vector< std::vector< cv::Ptr< cv::Mat > > > list_fundamental_;
00073   public:
00082     SequenceAnalyzer( MotionProcessor input_sequence,
00083       cv::Ptr<cv::FeatureDetector> feature_detector,
00084       cv::Ptr<cv::DescriptorExtractor> descriptor_extractor,
00085       cv::Ptr<PointsMatcher> match_algorithm );
00092     SequenceAnalyzer( 
00093       cv::Ptr<cv::FeatureDetector> feature_detector,
00094       cv::Ptr<cv::DescriptorExtractor> descriptor_extractor,
00095       cv::Ptr<PointsMatcher> match_algorithm );
00103     SequenceAnalyzer(
00104       std::vector< cv::Ptr< PointsToTrack > > &points_to_track,
00105       std::vector<cv::Mat> *images = NULL,
00106       cv::Ptr<PointsMatcher> match_algorithm = NULL );
00113     SequenceAnalyzer( cv::FileNode file,
00114       std::vector<cv::Mat> *images = NULL,
00115       cv::Ptr<PointsMatcher> match_algorithm = NULL );
00116 
00120     ~SequenceAnalyzer( void );
00128     void addImageToPipeline( cv::Mat image,
00129       cv::Ptr<PointsToTrack> points = cv::Ptr<PointsToTrack>( ) );
00136     void addImageToTracks( cv::Mat image,
00137       cv::Ptr<PointsToTrack> points = cv::Ptr<PointsToTrack>( ) );
00138 
00149     void computeMatches( uchar nbMaxThread = 64, bool printProgress = true );
00153     static void keepOnlyCorrectMatches(
00154       std::vector<TrackOfPoints>& tracks,
00155       unsigned int min_matches = 10,
00156       unsigned int min_consistance = 3);
00160     static inline void keepOnlyCorrectMatches(
00161       SequenceAnalyzer& tracks,
00162       unsigned int min_matches = 10,
00163       unsigned int min_consistance = 3)
00164       {
00165         keepOnlyCorrectMatches(tracks.getTracks(),min_matches,min_consistance);
00166       }
00170     inline std::vector<TrackOfPoints> &getTracks( ){return tracks_;};
00174     inline std::vector< cv::Ptr< PointsToTrack > > &getPoints( ){
00175       return points_to_track_;};
00176 
00181     inline ImagesGraphConnection& getImgGraph( )
00182     {
00183       if( !images_graph_.isGraphCreated( images_.size( ) ) )
00184         constructImagesGraph( );
00185       return images_graph_;
00186     };
00191     void showTracks( int timeBetweenImg=25 );
00197     void showTracks( int img_to_show, int timeBetweenImg );
00206     cv::Mat showTracksBetween( unsigned int img1, unsigned int img2,
00207       cv::Mat img = cv::Mat(), bool should_print = true );
00208 
00214     static void read( const cv::FileNode& node, SequenceAnalyzer& points );
00215 
00221     static void write( cv::FileStorage& fs, const SequenceAnalyzer& points );
00222 
00227     inline int getNumViews( ) const
00228     {
00229       unsigned int maxImg=0;
00230       std::vector<TrackOfPoints>::size_type key_size = tracks_.size( ),
00231         i=0;
00232       for ( i=0; i < key_size; i++ )
00233       {
00234         const TrackOfPoints &track = tracks_[ i ];
00235         int nviews = track.images_indexes_.size( );
00236         for( int j = 0;j<nviews;++j )
00237           if( maxImg<track.images_indexes_[ j ] )
00238             maxImg=track.images_indexes_[ j ];
00239       }
00240       return maxImg;
00241     }
00242 
00248     inline cv::Mat getImage( int idx ) { return images_[ idx ]; };
00249 
00256     void addMatches( std::vector<cv::DMatch> &newMatches,
00257       unsigned int img1, unsigned int img2 );
00258 
00263     void addTracks( std::vector<TrackOfPoints> &newTracks );
00267     void constructImagesGraph( );
00272     std::vector< unsigned int > getColors( );
00277     std::vector< cv::Vec3d > get3DStructure( );
00283     void showPointsOnImage(unsigned int i,
00284       const std::vector<cv::Vec2d>& pixelProjection);
00285 
00290     inline std::vector< cv::Ptr< PointsToTrack > > getPointsToTrack()
00291     { return points_to_track_; };
00296     inline cv::Ptr<PointsMatcher> getMatchAlgo()
00297     { return match_algorithm_->clone( true ); };
00298 
00305     static std::vector< cv::DMatch > simple_matching(
00306       cv::Ptr<PointsMatcher> point_matcher,
00307       cv::Ptr<PointsMatcher> point_matcher1,
00308       unsigned int mininum_points_matches = 10);
00309     
00315     static void removePointsWithoutProjection(
00316       SequenceAnalyzer &motion_estim );
00317   };
00318 
00319 }
00320 
00321 #endif
 All Classes Functions Variables