GSoC2011SfM  0.1
Google Summer of Code 2011: Structure from motion
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | Friends
OpencvSfM::SequenceAnalyzer Class Reference

This class tries to match points in the entire sequence. It follow ideas proposed by Noah Snavely: Modeling the World from Internet Photo Collections. More...

#include <SequenceAnalyzer.h>

List of all members.

Public Member Functions

 SequenceAnalyzer (MotionProcessor input_sequence, cv::Ptr< cv::FeatureDetector > feature_detector, cv::Ptr< cv::DescriptorExtractor > descriptor_extractor, cv::Ptr< PointsMatcher > match_algorithm)
 SequenceAnalyzer (cv::Ptr< cv::FeatureDetector > feature_detector, cv::Ptr< cv::DescriptorExtractor > descriptor_extractor, cv::Ptr< PointsMatcher > match_algorithm)
 SequenceAnalyzer (std::vector< cv::Ptr< PointsToTrack > > &points_to_track, std::vector< cv::Mat > *images=NULL, cv::Ptr< PointsMatcher > match_algorithm=NULL)
 SequenceAnalyzer (cv::FileNode file, std::vector< cv::Mat > *images=NULL, cv::Ptr< PointsMatcher > match_algorithm=NULL)
 ~SequenceAnalyzer (void)
void addImageToPipeline (cv::Mat image, cv::Ptr< PointsToTrack > points=cv::Ptr< PointsToTrack >())
void addImageToTracks (cv::Mat image, cv::Ptr< PointsToTrack > points=cv::Ptr< PointsToTrack >())
void computeMatches (uchar nbMaxThread=64, bool printProgress=true)
std::vector< TrackOfPoints > & getTracks ()
std::vector< cv::Ptr
< PointsToTrack > > & 
getPoints ()
ImagesGraphConnectiongetImgGraph ()
void showTracks (int timeBetweenImg=25)
void showTracks (int img_to_show, int timeBetweenImg)
cv::Mat showTracksBetween (unsigned int img1, unsigned int img2, cv::Mat img=cv::Mat(), bool should_print=true)
int getNumViews () const
cv::Mat getImage (int idx)
void addMatches (std::vector< cv::DMatch > &newMatches, unsigned int img1, unsigned int img2)
void addTracks (std::vector< TrackOfPoints > &newTracks)
void constructImagesGraph ()
std::vector< unsigned int > getColors ()
std::vector< cv::Vec3d > get3DStructure ()
void showPointsOnImage (unsigned int i, const std::vector< cv::Vec2d > &pixelProjection)
std::vector< cv::Ptr
< PointsToTrack > > 
getPointsToTrack ()
cv::Ptr< PointsMatchergetMatchAlgo ()

Static Public Member Functions

static void keepOnlyCorrectMatches (std::vector< TrackOfPoints > &tracks, unsigned int min_matches=10, unsigned int min_consistance=3)
static void keepOnlyCorrectMatches (SequenceAnalyzer &tracks, unsigned int min_matches=10, unsigned int min_consistance=3)
static void read (const cv::FileNode &node, SequenceAnalyzer &points)
static void write (cv::FileStorage &fs, const SequenceAnalyzer &points)
static std::vector< cv::DMatch > simple_matching (cv::Ptr< PointsMatcher > point_matcher, cv::Ptr< PointsMatcher > point_matcher1, unsigned int mininum_points_matches=10)
static void removePointsWithoutProjection (SequenceAnalyzer &motion_estim)

Protected Attributes

cv::Ptr< cv::FeatureDetector > feature_detector_
cv::Ptr< cv::DescriptorExtractor > descriptor_extractor_
std::vector< cv::Ptr
< PointsToTrack > > 
points_to_track_
std::vector< cv::Mat > images_
cv::Ptr< PointsMatchermatch_algorithm_
std::vector< cv::Ptr
< PointsMatcher > > 
matches_
std::vector< TrackOfPointstracks_
ImagesGraphConnection images_graph_
std::vector< std::vector
< cv::Ptr< cv::Mat > > > 
list_fundamental_

Static Protected Attributes

static int mininum_points_matches = 20
 Minimum points detected into an image to keep this estimation (set to 20)
static int mininum_image_matches = 2
 Minimum images connections in a track to keep this estimation (usually set to 2)

Friends

struct MatchingThread

Detailed Description

This class tries to match points in the entire sequence. It follow ideas proposed by Noah Snavely: Modeling the World from Internet Photo Collections.

This class process an input video to first extracts the features, then matches them and keeps them only when there is more than 2 pictures containing the point.

Definition at line 25 of file SequenceAnalyzer.h.


Constructor & Destructor Documentation

OpencvSfM::SequenceAnalyzer::SequenceAnalyzer ( MotionProcessor  input_sequence,
cv::Ptr< cv::FeatureDetector >  feature_detector,
cv::Ptr< cv::DescriptorExtractor >  descriptor_extractor,
cv::Ptr< PointsMatcher match_algorithm 
)

Constructor taking a MotionProcessor to load images and a features detector and descriptor to find matches.

Parameters:
input_sequenceinput images
feature_detectorAlgorithm to use for features detection ( see http://opencv.willowgarage.com/documentation/cpp/common_interfaces_for_feature_detection_and_descriptor_extraction.html#featuredetector )
descriptor_extractorAlgorithm to use for descriptors detection ( see http://opencv.willowgarage.com/documentation/cpp/common_interfaces_for_feature_detection_and_descriptor_extraction.html#descriptorextractor )
match_algorithmalgorithm to match points of each images

Definition at line 37 of file SequenceAnalyzer.cpp.

OpencvSfM::SequenceAnalyzer::SequenceAnalyzer ( cv::Ptr< cv::FeatureDetector >  feature_detector,
cv::Ptr< cv::DescriptorExtractor >  descriptor_extractor,
cv::Ptr< PointsMatcher match_algorithm 
)

Constructor with a features detector, descriptor and matcher.

Parameters:
feature_detectorAlgorithm to use for features detection ( see http://opencv.willowgarage.com/documentation/cpp/common_interfaces_for_feature_detection_and_descriptor_extraction.html#featuredetector )
descriptor_extractorAlgorithm to use for descriptors detection ( see http://opencv.willowgarage.com/documentation/cpp/common_interfaces_for_feature_detection_and_descriptor_extraction.html#descriptorextractor )
match_algorithmalgorithm to match points of each images

Definition at line 26 of file SequenceAnalyzer.cpp.

OpencvSfM::SequenceAnalyzer::SequenceAnalyzer ( std::vector< cv::Ptr< PointsToTrack > > &  points_to_track,
std::vector< cv::Mat > *  images = NULL,
cv::Ptr< PointsMatcher match_algorithm = NULL 
)

Constructor taking a vector of points to track and a PointsMatcher algorithm to find matches.

Parameters:
imagesinput images. Points should be in the same order!
points_to_tracklist of points to track with ( or not ) features
match_algorithmalgorithm to match points of each images

Definition at line 63 of file SequenceAnalyzer.cpp.

OpencvSfM::SequenceAnalyzer::SequenceAnalyzer ( cv::FileNode  file,
std::vector< cv::Mat > *  images = NULL,
cv::Ptr< PointsMatcher match_algorithm = NULL 
)

Constructor taking a list of images and a FileNode

Parameters:
imagesinput images. Points should be in the same order!
fileYAML file to get points and matches
match_algorithmalgorithm to match points of each images

Definition at line 79 of file SequenceAnalyzer.cpp.

OpencvSfM::SequenceAnalyzer::~SequenceAnalyzer ( void  )

Destructor of SequenceAnalyzer (nothing is released!)

Definition at line 93 of file SequenceAnalyzer.cpp.


Member Function Documentation

void OpencvSfM::SequenceAnalyzer::addImageToPipeline ( cv::Mat  image,
cv::Ptr< PointsToTrack points = cv::Ptr<PointsToTrack>( ) 
)

This method add new image to pipeline. When adding, if the matches are not computed, use automatically computeMatches to compute them! This new image will be added to tracks when calling computeMatches

Parameters:
imageNew image
pointsextracted points with features vectors.

Definition at line 97 of file SequenceAnalyzer.cpp.

Referenced by SequenceAnalyzer().

void OpencvSfM::SequenceAnalyzer::addImageToTracks ( cv::Mat  image,
cv::Ptr< PointsToTrack points = cv::Ptr<PointsToTrack>( ) 
)

This method add new image to tracks. When adding, if the matches are not computed, first compute them and mix them to existing tracks!

Parameters:
imageNew image
pointsextracted points with features vectors.

Definition at line 116 of file SequenceAnalyzer.cpp.

void OpencvSfM::SequenceAnalyzer::addMatches ( std::vector< cv::DMatch > &  newMatches,
unsigned int  img1,
unsigned int  img2 
)

This function add matches to tracks

Parameters:
newMatchesnew matches to add
img1index of source matches image
img2index of destination matches image

Definition at line 286 of file SequenceAnalyzer.cpp.

Referenced by OpencvSfM::EuclideanEstimator::addMoreMatches().

void OpencvSfM::SequenceAnalyzer::addTracks ( std::vector< TrackOfPoints > &  newTracks)

This function add new Tracks

Parameters:
newTracksnew Tracks to add

Definition at line 332 of file SequenceAnalyzer.cpp.

void OpencvSfM::SequenceAnalyzer::computeMatches ( uchar  nbMaxThread = 64,
bool  printProgress = true 
)

This method compute the matches between each points of each images. It first compute missing features descriptor, then train each matcher. Finally compute tracks of keypoints ( a track is a connected set of matching keypoints across multiple images )

Parameters:
nbMaxThreadst to a lower value if you experience out of memory exception. Indeed, if you have a lot of features, each thread will compute the descriptor for their working image, which can be really big...
printProgressset to true is you want to view progress.

Definition at line 188 of file SequenceAnalyzer.cpp.

void OpencvSfM::SequenceAnalyzer::constructImagesGraph ( )

This function constructs and feeds the images_graph_

Definition at line 637 of file SequenceAnalyzer.cpp.

std::vector< cv::Vec3d > OpencvSfM::SequenceAnalyzer::get3DStructure ( )

This function will create a list of 3D points corresponding to object viewed in the sequence

Definition at line 661 of file SequenceAnalyzer.cpp.

std::vector< unsigned int > OpencvSfM::SequenceAnalyzer::getColors ( )

This function will create a list of points color corresponding to object viewed in the sequence

Definition at line 674 of file SequenceAnalyzer.cpp.

cv::Mat OpencvSfM::SequenceAnalyzer::getImage ( int  idx) [inline]

get the ith image. No checks are performed!

Parameters:
idxindex of the wanted image
Returns:
Matrix of the wanted image

Definition at line 248 of file SequenceAnalyzer.h.

Referenced by OpencvSfM::EuclideanEstimator::addMoreMatches().

ImagesGraphConnection& OpencvSfM::SequenceAnalyzer::getImgGraph ( ) [inline]

Get the graph of image connections

Returns:
graph of image connections

Definition at line 181 of file SequenceAnalyzer.h.

Referenced by OpencvSfM::EuclideanEstimator::computeReconstruction().

cv::Ptr<PointsMatcher> OpencvSfM::SequenceAnalyzer::getMatchAlgo ( ) [inline]

Get a copy of the points Matcher algorithm from this sequence.

Returns:
points Matcher algorithm from this sequence.

Definition at line 296 of file SequenceAnalyzer.h.

int OpencvSfM::SequenceAnalyzer::getNumViews ( ) const [inline]

Use this function to know how many images are stored into tracks...

Returns:
numbers of images (and cameras) stored into tracks.

Definition at line 227 of file SequenceAnalyzer.h.

std::vector< cv::Ptr< PointsToTrack > >& OpencvSfM::SequenceAnalyzer::getPoints ( ) [inline]
std::vector< cv::Ptr< PointsToTrack > > OpencvSfM::SequenceAnalyzer::getPointsToTrack ( ) [inline]

Get the points for track from this sequence.

Returns:
points for track from this sequence.

Definition at line 290 of file SequenceAnalyzer.h.

Referenced by OpencvSfM::EuclideanEstimator::addMoreMatches().

std::vector<TrackOfPoints>& OpencvSfM::SequenceAnalyzer::getTracks ( ) [inline]
void OpencvSfM::SequenceAnalyzer::keepOnlyCorrectMatches ( std::vector< TrackOfPoints > &  tracks,
unsigned int  min_matches = 10,
unsigned int  min_consistance = 3 
) [static]

This method keep only tracks with more than mininum_image_matches

Definition at line 263 of file SequenceAnalyzer.cpp.

Referenced by OpencvSfM::EuclideanEstimator::addMoreMatches().

static void OpencvSfM::SequenceAnalyzer::keepOnlyCorrectMatches ( SequenceAnalyzer tracks,
unsigned int  min_matches = 10,
unsigned int  min_consistance = 3 
) [inline, static]

This method keep only tracks with more than mininum_image_matches

Definition at line 160 of file SequenceAnalyzer.h.

void OpencvSfM::SequenceAnalyzer::read ( const cv::FileNode &  node,
SequenceAnalyzer points 
) [static]

Load the sequence from a YAML file.

Parameters:
nodePreviously opened YAML file node
pointsoutput

Definition at line 497 of file SequenceAnalyzer.cpp.

Referenced by SequenceAnalyzer().

void OpencvSfM::SequenceAnalyzer::removePointsWithoutProjection ( SequenceAnalyzer motion_estim) [static]

Once points have been triangulated, use this method to remove 2D points who don't have 3D projection

Parameters:
motion_estimsequence to work on

Definition at line 785 of file SequenceAnalyzer.cpp.

void OpencvSfM::SequenceAnalyzer::showPointsOnImage ( unsigned int  i,
const std::vector< cv::Vec2d > &  pixelProjection 
)

Use this function to show 2D points into ith image

Parameters:
iindex of wanted image
pixelProjectionlist of 2D points

Definition at line 687 of file SequenceAnalyzer.cpp.

void OpencvSfM::SequenceAnalyzer::showTracks ( int  timeBetweenImg = 25)

Use this function to print the sequence of matches

Parameters:
timeBetweenImgsee cv::waitKey for the value

Definition at line 346 of file SequenceAnalyzer.cpp.

void OpencvSfM::SequenceAnalyzer::showTracks ( int  img_to_show,
int  timeBetweenImg 
)

Use this function to print the sequence of matches

Parameters:
img_to_showindex of image whose tracks will be shown.
timeBetweenImgsee cv::waitKey for the value

Definition at line 398 of file SequenceAnalyzer.cpp.

cv::Mat OpencvSfM::SequenceAnalyzer::showTracksBetween ( unsigned int  img1,
unsigned int  img2,
cv::Mat  img = cv::Mat(),
bool  should_print = true 
)

Use this function to print the matches between two images

Parameters:
img1first index of image
img2second index of image
imgimage where tracks will be print
should_printif true the output is displayed
Returns:
image with tracks printed on it

Definition at line 447 of file SequenceAnalyzer.cpp.

std::vector< cv::DMatch > OpencvSfM::SequenceAnalyzer::simple_matching ( cv::Ptr< PointsMatcher point_matcher,
cv::Ptr< PointsMatcher point_matcher1,
unsigned int  mininum_points_matches = 10 
) [static]

This will find matches between two points matchers

Parameters:
point_matcherfirst image
point_matcher1second image
mininum_points_matchesminimum matches allowed

Definition at line 705 of file SequenceAnalyzer.cpp.

Referenced by addImageToTracks(), and OpencvSfM::EuclideanEstimator::addMoreMatches().

void OpencvSfM::SequenceAnalyzer::write ( cv::FileStorage &  fs,
const SequenceAnalyzer points 
) [static]

Save the sequence into a YAML file.

Parameters:
fsPreviously opened YAML file node
pointssequence to save...

Definition at line 580 of file SequenceAnalyzer.cpp.


Member Data Documentation

cv::Ptr<cv::DescriptorExtractor> OpencvSfM::SequenceAnalyzer::descriptor_extractor_ [protected]

optional, method to use for feature extraction

Definition at line 38 of file SequenceAnalyzer.h.

Referenced by addImageToPipeline(), addImageToTracks(), and removePointsWithoutProjection().

cv::Ptr<cv::FeatureDetector> OpencvSfM::SequenceAnalyzer::feature_detector_ [protected]

optional, method to use for feature detection

Definition at line 34 of file SequenceAnalyzer.h.

Referenced by addImageToPipeline(), addImageToTracks(), and removePointsWithoutProjection().

std::vector<cv::Mat> OpencvSfM::SequenceAnalyzer::images_ [protected]

Graph of images relations ( value ( i,j ) correspond to the numbers of matches between theses two images

Definition at line 65 of file SequenceAnalyzer.h.

Referenced by constructImagesGraph().

std::vector< std::vector< cv::Ptr< cv::Mat > > > OpencvSfM::SequenceAnalyzer::list_fundamental_ [protected]

A list of the fundamental matrix between each points* this list can have some NULL values as the fundamental matrix don't exist between every images... This matrix is uper-triangular, that is [2][1] exist, but [1][2] not...

Definition at line 72 of file SequenceAnalyzer.h.

Referenced by computeMatches().

The matcher algorithm we should use to find matches.

Definition at line 50 of file SequenceAnalyzer.h.

Referenced by addImageToTracks(), computeMatches(), read(), and SequenceAnalyzer().

std::vector< cv::Ptr< PointsMatcher > > OpencvSfM::SequenceAnalyzer::matches_ [protected]

A matcher for each picture. Its role is to find quickly matches between i^th picture and other images.

Definition at line 55 of file SequenceAnalyzer.h.

Referenced by read().

std::vector< cv::Ptr< PointsToTrack > > OpencvSfM::SequenceAnalyzer::points_to_track_ [protected]

List of each tracks found. A track is a connected set of matching keypoints across multiple images

Definition at line 60 of file SequenceAnalyzer.h.

Referenced by addImageToTracks(), addMatches(), addTracks(), computeMatches(), constructImagesGraph(), get3DStructure(), getColors(), read(), removePointsWithoutProjection(), showTracks(), showTracksBetween(), and write().


The documentation for this class was generated from the following files:
 All Classes Functions Variables