GSoC2011SfM
0.1
Google Summer of Code 2011: Structure from motion
|
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>
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 () |
ImagesGraphConnection & | getImgGraph () |
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< PointsMatcher > | getMatchAlgo () |
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< PointsMatcher > | match_algorithm_ |
std::vector< cv::Ptr < PointsMatcher > > | matches_ |
std::vector< TrackOfPoints > | tracks_ |
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 |
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.
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.
input_sequence | input images |
feature_detector | Algorithm to use for features detection ( see http://opencv.willowgarage.com/documentation/cpp/common_interfaces_for_feature_detection_and_descriptor_extraction.html#featuredetector ) |
descriptor_extractor | Algorithm to use for descriptors detection ( see http://opencv.willowgarage.com/documentation/cpp/common_interfaces_for_feature_detection_and_descriptor_extraction.html#descriptorextractor ) |
match_algorithm | algorithm 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.
feature_detector | Algorithm to use for features detection ( see http://opencv.willowgarage.com/documentation/cpp/common_interfaces_for_feature_detection_and_descriptor_extraction.html#featuredetector ) |
descriptor_extractor | Algorithm to use for descriptors detection ( see http://opencv.willowgarage.com/documentation/cpp/common_interfaces_for_feature_detection_and_descriptor_extraction.html#descriptorextractor ) |
match_algorithm | algorithm 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.
images | input images. Points should be in the same order! |
points_to_track | list of points to track with ( or not ) features |
match_algorithm | algorithm 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
images | input images. Points should be in the same order! |
file | YAML file to get points and matches |
match_algorithm | algorithm 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.
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
image | New image |
points | extracted 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!
image | New image |
points | extracted 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
newMatches | new matches to add |
img1 | index of source matches image |
img2 | index 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
newTracks | new 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 )
nbMaxThread | st 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... |
printProgress | set 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!
idx | index 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
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.
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...
Definition at line 227 of file SequenceAnalyzer.h.
std::vector< cv::Ptr< PointsToTrack > >& OpencvSfM::SequenceAnalyzer::getPoints | ( | ) | [inline] |
This method can be used to get the points
Definition at line 174 of file SequenceAnalyzer.h.
Referenced by OpencvSfM::EuclideanEstimator::bundleAdjustement(), OpencvSfM::EuclideanEstimator::cameraResection(), OpencvSfM::EuclideanEstimator::computeReconstruction(), OpencvSfM::StructureEstimator::computeStructure(), OpencvSfM::EuclideanEstimator::initialReconstruction(), and OpencvSfM::StructureEstimator::removeOutliersTracks().
std::vector< cv::Ptr< PointsToTrack > > OpencvSfM::SequenceAnalyzer::getPointsToTrack | ( | ) | [inline] |
Get the 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] |
This method can be used to get the tracks
Definition at line 170 of file SequenceAnalyzer.h.
Referenced by OpencvSfM::EuclideanEstimator::computeReconstruction(), OpencvSfM::StructureEstimator::computeStructure(), OpencvSfM::EuclideanEstimator::initialReconstruction(), keepOnlyCorrectMatches(), and OpencvSfM::StructureEstimator::removeOutliersTracks().
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.
node | Previously opened YAML file node |
points | output |
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
motion_estim | sequence 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
i | index of wanted image |
pixelProjection | list 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
timeBetweenImg | see 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
img_to_show | index of image whose tracks will be shown. |
timeBetweenImg | see 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
img1 | first index of image |
img2 | second index of image |
img | image where tracks will be print |
should_print | if true the output is displayed |
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
point_matcher | first image |
point_matcher1 | second image |
mininum_points_matches | minimum 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.
fs | Previously opened YAML file node |
points | sequence to save... |
Definition at line 580 of file SequenceAnalyzer.cpp.
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] |
List of input images
Definition at line 46 of file SequenceAnalyzer.h.
Referenced by addImageToPipeline(), addImageToTracks(), read(), removePointsWithoutProjection(), SequenceAnalyzer(), showPointsOnImage(), showTracks(), and showTracksBetween().
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().
cv::Ptr<PointsMatcher> OpencvSfM::SequenceAnalyzer::match_algorithm_ [protected] |
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] |
A list of points for each picture
Definition at line 42 of file SequenceAnalyzer.h.
Referenced by addImageToPipeline(), addImageToTracks(), computeMatches(), constructImagesGraph(), read(), removePointsWithoutProjection(), showTracks(), showTracksBetween(), and write().
std::vector<TrackOfPoints> OpencvSfM::SequenceAnalyzer::tracks_ [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().