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

A class used for matching descriptors that can be described as vectors in a finite-dimensional space. More...

#include <PointsMatcher.h>

Inheritance diagram for OpencvSfM::PointsMatcher:
OpencvSfM::MatcherSparseFlow OpencvSfM::PointsMatcherOpticalFlow

List of all members.

Public Member Functions

 PointsMatcher (const cv::Ptr< cv::DescriptorMatcher > &matcher)
 PointsMatcher (const PointsMatcher &copy)
virtual ~PointsMatcher ()
virtual void add (cv::Ptr< PointsToTrack > pointCollection)
virtual void clear ()
virtual void train ()
virtual bool isMaskSupported ()
virtual bool empty () const
virtual cv::Ptr< PointsMatcherclone (bool emptyTrainData=true)
virtual void match (cv::Ptr< PointsToTrack > queryPoints, std::vector< cv::DMatch > &matches, const std::vector< cv::Mat > &masks=std::vector< cv::Mat >())
virtual void knnMatch (cv::Ptr< PointsToTrack > queryPoints, std::vector< std::vector< cv::DMatch > > &matches, int k, const std::vector< cv::Mat > &masks=std::vector< cv::Mat >(), bool compactResult=true)
virtual void radiusMatch (cv::Ptr< PointsToTrack > queryPoints, std::vector< std::vector< cv::DMatch > > &matches, float maxDistance, const std::vector< cv::Mat > &masks=std::vector< cv::Mat >(), bool compactResult=true)
virtual void crossMatch (cv::Ptr< PointsMatcher > otherMatcher, std::vector< cv::DMatch > &matches, const std::vector< cv::Mat > &masks=std::vector< cv::Mat >())
const cv::KeyPoint & getKeypoint (int numKey) const

Static Public Member Functions

static cv::Ptr< PointsMatchercreate (std::string match_algo)
static void drawMatches (const cv::Mat &img1, const std::vector< cv::KeyPoint > &keypoints1, const std::vector< cv::KeyPoint > &keypoints2, const std::vector< cv::DMatch > &matches1to2, cv::Mat &outImg, const cv::Scalar &matchColor=cv::Scalar::all(-1), const cv::Scalar &singlePointColor=cv::Scalar::all(-1), const std::vector< char > &matchesMask=std::vector< char >(), int flags=cv::DrawMatchesFlags::DEFAULT)
static void read (const cv::FileNode &node, PointsMatcher &points)
static void write (cv::FileStorage &fs, const PointsMatcher &points)

Protected Member Functions

 DECLARE_MUTEX (thread_concurr)
 PointsMatcher ()

Protected Attributes

cv::Ptr< cv::DescriptorMatcher > matcher_
 Algorithm used to find matches...
std::vector< cv::Ptr
< PointsToTrack > > 
pointCollection_
 Vector of points used to compute matches...

Detailed Description

A class used for matching descriptors that can be described as vectors in a finite-dimensional space.

Any Matcher that inherit from DescriptorMatcher can be used ( For example, you can use FlannBasedMatcher or BruteForceMatcher ).

Definition at line 17 of file PointsMatcher.h.


Constructor & Destructor Documentation

OpencvSfM::PointsMatcher::PointsMatcher ( const cv::Ptr< cv::DescriptorMatcher > &  matcher)

Constructor. Need a matcher algorithm...

Parameters:
matcherPtr on a matcher. See for available matcher: http://opencv.willowgarage.com/documentation/cpp/features2d_common_interfaces_of_descriptor_matchers.html#descriptormatcher

Definition at line 20 of file PointsMatcher.cpp.

OpencvSfM::PointsMatcher::PointsMatcher ( const PointsMatcher copy)

Copy constructor.

Definition at line 33 of file PointsMatcher.cpp.

OpencvSfM::PointsMatcher::~PointsMatcher ( void  ) [virtual]

Destructor...

Definition at line 40 of file PointsMatcher.cpp.

OpencvSfM::PointsMatcher::PointsMatcher ( ) [protected]

This constructor is only available for inherited classes!

Definition at line 27 of file PointsMatcher.cpp.

Referenced by clone().


Member Function Documentation

void OpencvSfM::PointsMatcher::add ( cv::Ptr< PointsToTrack pointCollection) [virtual]

Use this function to add data used to find matches

Parameters:
pointCollectionpoints computed using various methods. Please be carful to get compatible points ( that is with descriptors if matcher need some )

Definition at line 51 of file PointsMatcher.cpp.

void OpencvSfM::PointsMatcher::clear ( ) [virtual]

If needed, you can clear the training data using this method.

Reimplemented in OpencvSfM::PointsMatcherOpticalFlow.

Definition at line 58 of file PointsMatcher.cpp.

Ptr< PointsMatcher > OpencvSfM::PointsMatcher::clone ( bool  emptyTrainData = true) [virtual]

Clone the matcher.

Parameters:
emptyTrainDataIIf emptyTrainData is false the method create deep copy of the object, i.e. copies both parameters and train data. If emptyTrainData is true the method create object copy with current parameters but with empty train data..
Returns:
An other PointsMatcher instance

Reimplemented in OpencvSfM::PointsMatcherOpticalFlow, and OpencvSfM::MatcherSparseFlow.

Definition at line 170 of file PointsMatcher.cpp.

Referenced by OpencvSfM::MatchingThread::operator()().

static cv::Ptr<PointsMatcher> OpencvSfM::PointsMatcher::create ( std::string  match_algo) [inline, static]

Use this function to create a point matcher using the name of a matching algorithm (see http://opencv.willowgarage.com/documentation/cpp/features2d_common_interfaces_of_descriptor_matchers.html)

Parameters:
match_algoname of the wanted algorithm
Returns:
new PointsMatcher

Definition at line 41 of file PointsMatcher.h.

void OpencvSfM::PointsMatcher::crossMatch ( cv::Ptr< PointsMatcher otherMatcher,
std::vector< cv::DMatch > &  matches,
const std::vector< cv::Mat > &  masks = std::vector<cv::Mat>( ) 
) [virtual]

Using an other matchers given in parameters, recompute a matching in inverse order and keep only matches which are two-ways.

Parameters:
otherMatcherQuery set of points and descriptors.
matchesFirst guess of matches... Will be updated to contain only two-way matches ( can be empty ).
masksspecifying permissible matches between input query and train matrices of descriptors.

Definition at line 181 of file PointsMatcher.cpp.

OpencvSfM::PointsMatcher::DECLARE_MUTEX ( thread_concurr  ) [protected]

In order to be able to match points in threads, we have to take care of interprocess access.

void OpencvSfM::PointsMatcher::drawMatches ( const cv::Mat &  img1,
const std::vector< cv::KeyPoint > &  keypoints1,
const std::vector< cv::KeyPoint > &  keypoints2,
const std::vector< cv::DMatch > &  matches1to2,
cv::Mat &  outImg,
const cv::Scalar &  matchColor = cv::Scalar::all( -1 ),
const cv::Scalar &  singlePointColor = cv::Scalar::all( -1 ),
const std::vector< char > &  matchesMask = std::vector<char>( ),
int  flags = cv::DrawMatchesFlags::DEFAULT 
) [static]

This function draw keypoints and matches. Contrary to cv::drawMatches, only the first image is used to draw matches...

Parameters:
img1First source image.
keypoints1Keypoints from first source image.
keypoints2Keypoints from second source image.
matches1to2Matches from first image to second one, i.e. keypoints1[ i ] has corresponding point keypoints2[ matches[ i ]] .
outImgOutput image. Its content depends on flags value what is drawn in output image. See below possible flags bit values.
matchColor– Color of matches ( lines and connected keypoints ). If matchColor==Scalar::all( -1 ) color will be generated randomly.
singlePointColor– Color of single keypoints ( circles ), i.e. keypoints not having the matches. If singlePointColor==Scalar::all( -1 ) color will be generated randomly.
matchesMask– Mask determining which matches will be drawn. If mask is empty all matches will be drawn.
flags– Each bit of flags sets some feature of drawing. Possible flags bit values is defined by DrawMatchesFlags , see http://opencv.willowgarage.com/documentation/cpp/features2d_drawing_function_of_keypoints_and_matches.html#cv-drawmatches.

Definition at line 227 of file PointsMatcher.cpp.

Referenced by OpencvSfM::SequenceAnalyzer::showTracks(), and OpencvSfM::SequenceAnalyzer::showTracksBetween().

bool OpencvSfM::PointsMatcher::empty ( ) const [virtual]

Use to know if matching are available

Returns:
true if matching has been performed

Reimplemented in OpencvSfM::PointsMatcherOpticalFlow.

Definition at line 165 of file PointsMatcher.cpp.

const cv::KeyPoint & OpencvSfM::PointsMatcher::getKeypoint ( int  numKey) const

Get a keypoint

Parameters:
numKeyindex of the wanted point
Returns:
keypoint using the cv::Keypoint format

Definition at line 45 of file PointsMatcher.cpp.

bool OpencvSfM::PointsMatcher::isMaskSupported ( ) [virtual]

Use this method to know if mask are supported with current matcher

Returns:
true if matcher can use mask

Reimplemented in OpencvSfM::PointsMatcherOpticalFlow.

Definition at line 97 of file PointsMatcher.cpp.

virtual void OpencvSfM::PointsMatcher::knnMatch ( cv::Ptr< PointsToTrack queryPoints,
std::vector< std::vector< cv::DMatch > > &  matches,
int  k,
const std::vector< cv::Mat > &  masks = std::vector< cv::Mat >(),
bool  compactResult = true 
) [virtual]

Find the k best matches for each descriptor from a query set with train descriptors.

Parameters:
queryPointsQuery set of points and descriptors.
matchesMathes. Each matches[ i ] is k or less matches for the same query descriptor.
kCount of best matches will be found per each query descriptor ( or less if it’s not possible ).
masksspecifying permissible matches between input query and train matrices of descriptors.
compactResult– It’s used when mask ( or masks ) is not empty. If compactResult is false matches vector will have the same size as queryDescriptors rows. If compactResult is true matches vector will not contain matches for fully masked out query descriptors.

Reimplemented in OpencvSfM::PointsMatcherOpticalFlow, and OpencvSfM::MatcherSparseFlow.

void OpencvSfM::PointsMatcher::match ( cv::Ptr< PointsToTrack queryPoints,
std::vector< cv::DMatch > &  matches,
const std::vector< cv::Mat > &  masks = std::vector<cv::Mat>( ) 
) [virtual]

Find the k best matches for each descriptor from a query set with train descriptors.

Parameters:
queryPointsQuery set of points and descriptors.
matchesMathes. If some query descriptor ( keypoint ) masked out in mask no match will be added for this descriptor. So matches size may be less than query keypoints count.
masksThe set of masks. Each masks[ i ] specifies permissible matches between input query keypoints and stored train keypointss from i-th image.

Reimplemented in OpencvSfM::PointsMatcherOpticalFlow, and OpencvSfM::MatcherSparseFlow.

Definition at line 102 of file PointsMatcher.cpp.

Referenced by crossMatch().

virtual void OpencvSfM::PointsMatcher::radiusMatch ( cv::Ptr< PointsToTrack queryPoints,
std::vector< std::vector< cv::DMatch > > &  matches,
float  maxDistance,
const std::vector< cv::Mat > &  masks = std::vector< cv::Mat >(),
bool  compactResult = true 
) [virtual]

Find the best matches for each query descriptor which have distance less than given threshold.

Parameters:
queryPointsQuery set of points and descriptors.
matchesEach matches[ i ] is k or less matches for the same query descriptor.
maxDistanceThe threshold to found match distances.
masksspecifying permissible matches between input query and train matrices of descriptors.
compactResult– It’s used when mask ( or masks ) is not empty. If compactResult is false matches vector will have the same size as queryDescriptors rows. If compactResult is true matches vector will not contain matches for fully masked out query descriptors.

Reimplemented in OpencvSfM::PointsMatcherOpticalFlow, and OpencvSfM::MatcherSparseFlow.

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

Load the matches from a YAML file.

Parameters:
nodePreviously opened YAML file node
pointsoutput

Definition at line 284 of file PointsMatcher.cpp.

void OpencvSfM::PointsMatcher::train ( ) [virtual]

When using matcher which need training, use this method to start the training.

Reimplemented in OpencvSfM::PointsMatcherOpticalFlow.

Definition at line 69 of file PointsMatcher.cpp.

Referenced by crossMatch(), OpencvSfM::PointsMatcherOpticalFlow::knnMatch(), match(), and OpencvSfM::PointsMatcherOpticalFlow::radiusMatch().

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

Save the matches into a YAML file.

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

Definition at line 309 of file PointsMatcher.cpp.


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