cv::DescriptorMatcher Class Reference abstract
2D 特征框架 » Descriptor Matchers

Abstract base class for matching keypoint descriptors. 更多...

#include <opencv2/features2d.hpp>

Inheritance diagram for cv::DescriptorMatcher:
cv::Algorithm cv::BFMatcher cv::FlannBasedMatcher

class DescriptorCollection

公共类型

enum MatcherType {
FLANNBASED = 1,
BRUTEFORCE = 2,
BRUTEFORCE_L1 = 3,
BRUTEFORCE_HAMMING = 4,
BRUTEFORCE_HAMMINGLUT = 5,
BRUTEFORCE_SL2 = 6
}

Public Member Functions

virtual ~DescriptorMatcher ()
virtual void add ( InputArrayOfArrays descriptors)
Adds descriptors to train a CPU(trainDescCollectionis) or GPU(utrainDescCollectionis) descriptor collection. 更多...
virtual void clear () CV_OVERRIDE
Clears the train descriptor collections. 更多...
virtual Ptr < DescriptorMatcher > clone (bool emptyTrainData=false) const =0
Clones the matcher. 更多...
virtual bool empty () const CV_OVERRIDE
Returns true if there are no train descriptors in the both collections. 更多...
const std::vector< Mat > & getTrainDescriptors () const
Returns a constant link to the train descriptor collection trainDescCollection . 更多...
virtual bool isMaskSupported () const =0
Returns true if the descriptor matcher supports masking permissible matches. 更多...
void knnMatch ( InputArray queryDescriptors, InputArray trainDescriptors, std::vector< std::vector< DMatch > > &matches, int k, InputArray mask= noArray (), bool compactResult=false) const
Finds the k best matches for each descriptor from a query set. 更多...
void knnMatch ( InputArray queryDescriptors, std::vector< std::vector< DMatch > > &matches, int k, InputArrayOfArrays masks= noArray (), bool compactResult=false)
void match ( InputArray queryDescriptors, InputArray trainDescriptors, std::vector< DMatch > &matches, InputArray mask= noArray ()) const
Finds the best match for each descriptor from a query set. 更多...
void match ( InputArray queryDescriptors, std::vector< DMatch > &matches, InputArrayOfArrays masks= noArray ())
void radiusMatch ( InputArray queryDescriptors, InputArray trainDescriptors, std::vector< std::vector< DMatch > > &matches, float maxDistance, InputArray mask= noArray (), bool compactResult=false) const
For each query descriptor, finds the training descriptors not farther than the specified distance. 更多...
void radiusMatch ( InputArray queryDescriptors, std::vector< std::vector< DMatch > > &matches, float maxDistance, InputArrayOfArrays masks= noArray (), bool compactResult=false)
void read (const 字符串 &fileName)
virtual void read (const FileNode &) CV_OVERRIDE
Reads algorithm parameters from a file storage. 更多...
virtual void train ()
Trains a descriptor matcher. 更多...
void write (const 字符串 &fileName) const
virtual void write ( FileStorage &) const CV_OVERRIDE
Stores algorithm parameters in a file storage. 更多...
void write (const Ptr < FileStorage > &fs, const 字符串 &name= 字符串 ()) const
- Public Member Functions inherited from cv::Algorithm
Algorithm ()
virtual ~Algorithm ()
virtual 字符串 getDefaultName () const
virtual void save (const 字符串 &filename) const
void write (const Ptr < FileStorage > &fs, const 字符串 &name= 字符串 ()) const
simplified API for language bindings This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. 更多...

Static Public Member Functions

static Ptr < DescriptorMatcher > create (const 字符串 &descriptorMatcherType)
Creates a descriptor matcher of a given type with the default parameters (using default constructor). 更多...
static Ptr < DescriptorMatcher > create (const DescriptorMatcher::MatcherType &matcherType)
- Static Public Member Functions inherited from cv::Algorithm
template<typename _Tp >
static Ptr < _Tp > load (const 字符串 &filename, const 字符串 &objname= 字符串 ())
Loads algorithm from the file. 更多...
template<typename _Tp >
static Ptr < _Tp > loadFromString (const 字符串 &strModel, const 字符串 &objname= 字符串 ())
Loads algorithm from a String. 更多...
template<typename _Tp >
static Ptr < _Tp > read (const FileNode &fn)
Reads algorithm from the file node. 更多...

Protected Member Functions

void checkMasks ( InputArrayOfArrays masks, int queryDescriptorsCount) const
virtual void knnMatchImpl ( InputArray queryDescriptors, std::vector< std::vector< DMatch > > &matches, int k, InputArrayOfArrays masks= noArray (), bool compactResult=false)=0
virtual void radiusMatchImpl ( InputArray queryDescriptors, std::vector< std::vector< DMatch > > &matches, float maxDistance, InputArrayOfArrays masks= noArray (), bool compactResult=false)=0
- Protected Member Functions inherited from cv::Algorithm
void writeFormat ( FileStorage &fs) const

Static Protected Member Functions

static Mat clone_op ( Mat m)
static bool isMaskedOut ( InputArrayOfArrays masks, int queryIdx)
static bool isPossibleMatch ( InputArray mask, int queryIdx, int trainIdx)

Protected Attributes

std::vector< Mat > trainDescCollection
Collection of descriptors from train images. 更多...
std::vector< UMat > utrainDescCollection

详细描述

Abstract base class for matching keypoint descriptors.

It has two groups of match methods: for matching descriptors of an image with another image or with an image set.

Member Enumeration Documentation

MatcherType

枚举器
FLANNBASED
BRUTEFORCE
BRUTEFORCE_L1
BRUTEFORCE_HAMMING
BRUTEFORCE_HAMMINGLUT
BRUTEFORCE_SL2

Constructor & Destructor Documentation

~DescriptorMatcher()

virtual cv::DescriptorMatcher::~DescriptorMatcher ( )
virtual

成员函数文档编制

add()

virtual void cv::DescriptorMatcher::add ( InputArrayOfArrays descriptors )
virtual
Python:
None = cv.DescriptorMatcher.add( descriptors )

Adds descriptors to train a CPU(trainDescCollectionis) or GPU(utrainDescCollectionis) descriptor collection.

If the collection is not empty, the new descriptors are added to existing train descriptors.

参数
descriptors Descriptors to add. Each descriptors[i] is a set of descriptors from the same train image.

Reimplemented in cv::FlannBasedMatcher .

checkMasks()

void cv::DescriptorMatcher::checkMasks ( InputArrayOfArrays masks ,
int queryDescriptorsCount
) const
protected

clear()

virtual void cv::DescriptorMatcher::clear ( )
virtual
Python:
None = cv.DescriptorMatcher.clear( )

Clears the train descriptor collections.

Reimplemented from cv::Algorithm .

Reimplemented in cv::FlannBasedMatcher .

clone()

virtual Ptr < DescriptorMatcher > cv::DescriptorMatcher::clone ( bool emptyTrainData = false ) const
pure virtual
Python:
retval = cv.DescriptorMatcher.clone( [, emptyTrainData] )

Clones the matcher.

参数
emptyTrainData If emptyTrainData is false, the method creates a deep copy of the object, that is, copies both parameters and train data. If emptyTrainData is true, the method creates an object copy with the current parameters but with empty train data.

Implemented in cv::FlannBasedMatcher ,和 cv::BFMatcher .

clone_op()

static Mat cv::DescriptorMatcher::clone_op ( Mat m )
inline static protected

create() [1/2]

static Ptr < DescriptorMatcher > cv::DescriptorMatcher::create ( const 字符串 & descriptorMatcherType )
static
Python:
retval = cv.DescriptorMatcher_create( descriptorMatcherType )
retval = cv.DescriptorMatcher_create( matcherType )

Creates a descriptor matcher of a given type with the default parameters (using default constructor).

参数
descriptorMatcherType Descriptor matcher type. Now the following matcher types are supported:
  • BruteForce (it uses L2 )
  • BruteForce-L1
  • BruteForce-Hamming
  • BruteForce-Hamming(2)
  • FlannBased

create() [2/2]

static Ptr < DescriptorMatcher > cv::DescriptorMatcher::create ( const DescriptorMatcher::MatcherType & matcherType )
static
Python:
retval = cv.DescriptorMatcher_create( descriptorMatcherType )
retval = cv.DescriptorMatcher_create( matcherType )

empty()

virtual bool cv::DescriptorMatcher::empty ( ) const
virtual
Python:
retval = cv.DescriptorMatcher.empty( )

Returns true if there are no train descriptors in the both collections.

Reimplemented from cv::Algorithm .

getTrainDescriptors()

const std::vector< Mat >& cv::DescriptorMatcher::getTrainDescriptors ( ) const
Python:
retval = cv.DescriptorMatcher.getTrainDescriptors( )

Returns a constant link to the train descriptor collection trainDescCollection .

isMaskedOut()

static bool cv::DescriptorMatcher::isMaskedOut ( InputArrayOfArrays masks ,
int queryIdx
)
static protected

isMaskSupported()

virtual bool cv::DescriptorMatcher::isMaskSupported ( ) const
pure virtual
Python:
retval = cv.DescriptorMatcher.isMaskSupported( )

Returns true if the descriptor matcher supports masking permissible matches.

Implemented in cv::FlannBasedMatcher ,和 cv::BFMatcher .

isPossibleMatch()

static bool cv::DescriptorMatcher::isPossibleMatch ( InputArray mask ,
int queryIdx ,
int trainIdx
)
static protected

knnMatch() [1/2]

void cv::DescriptorMatcher::knnMatch ( InputArray queryDescriptors ,
InputArray trainDescriptors ,
std::vector< std::vector< DMatch > > & matches ,
int k ,
InputArray mask = noArray () ,
bool compactResult = false
) const
Python:
matches = cv.DescriptorMatcher.knnMatch( queryDescriptors, trainDescriptors, k[, mask[, compactResult]] )
matches = cv.DescriptorMatcher.knnMatch( queryDescriptors, k[, masks[, compactResult]] )

Finds the k best matches for each descriptor from a query set.

参数
queryDescriptors Query set of descriptors.
trainDescriptors Train set of descriptors. This set is not added to the train descriptors collection stored in the class object.
mask Mask specifying permissible matches between an input query and train matrices of descriptors.
matches Matches. Each matches[i] is k or less matches for the same query descriptor.
k Count of best matches found per each query descriptor or less if a query descriptor has less than k possible matches in total.
compactResult Parameter used when the mask (or masks) is not empty. If compactResult is false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, the matches vector does not contain matches for fully masked-out query descriptors.

These extended variants of DescriptorMatcher::match methods find several best matches for each query descriptor. The matches are returned in the distance increasing order. See DescriptorMatcher::match for the details about query and train descriptors.

knnMatch() [2/2]

void cv::DescriptorMatcher::knnMatch ( InputArray queryDescriptors ,
std::vector< std::vector< DMatch > > & matches ,
int k ,
InputArrayOfArrays masks = noArray () ,
bool compactResult = false
)
Python:
matches = cv.DescriptorMatcher.knnMatch( queryDescriptors, trainDescriptors, k[, mask[, compactResult]] )
matches = cv.DescriptorMatcher.knnMatch( queryDescriptors, k[, masks[, compactResult]] )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

参数
queryDescriptors Query set of descriptors.
matches Matches. Each matches[i] is k or less matches for the same query descriptor.
k Count of best matches found per each query descriptor or less if a query descriptor has less than k possible matches in total.
masks Set of masks. Each masks[i] specifies permissible matches between the input query descriptors and stored train descriptors from the i-th image trainDescCollection[i].
compactResult Parameter used when the mask (or masks) is not empty. If compactResult is false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, the matches vector does not contain matches for fully masked-out query descriptors.

knnMatchImpl()

virtual void cv::DescriptorMatcher::knnMatchImpl ( InputArray queryDescriptors ,
std::vector< std::vector< DMatch > > & matches ,
int k ,
InputArrayOfArrays masks = noArray () ,
bool compactResult = false
)
protected pure virtual

In fact the matching is implemented only by the following two methods. These methods suppose that the class object has been trained already. Public match methods call these methods after calling train() .

Implemented in cv::FlannBasedMatcher ,和 cv::BFMatcher .

match() [1/2]

void cv::DescriptorMatcher::match ( InputArray queryDescriptors ,
InputArray trainDescriptors ,
std::vector< DMatch > & matches ,
InputArray mask = noArray ()
) const
Python:
matches = cv.DescriptorMatcher.match( queryDescriptors, trainDescriptors[, mask] )
matches = cv.DescriptorMatcher.match( queryDescriptors[, masks] )

Finds the best match for each descriptor from a query set.

参数
queryDescriptors Query set of descriptors.
trainDescriptors Train set of descriptors. This set is not added to the train descriptors collection stored in the class object.
matches Matches. If a query descriptor is masked out in mask , no match is added for this descriptor. So, matches size may be smaller than the query descriptors count.
mask Mask specifying permissible matches between an input query and train matrices of descriptors.

In the first variant of this method, the train descriptors are passed as an input argument. In the second variant of the method, train descriptors collection that was set by DescriptorMatcher::add is used. Optional mask (or masks) can be passed to specify which query and training descriptors can be matched. Namely, queryDescriptors[i] can be matched with trainDescriptors[j] only if mask.at<uchar>(i,j) is non-zero.

match() [2/2]

void cv::DescriptorMatcher::match ( InputArray queryDescriptors ,
std::vector< DMatch > & matches ,
InputArrayOfArrays masks = noArray ()
)
Python:
matches = cv.DescriptorMatcher.match( queryDescriptors, trainDescriptors[, mask] )
matches = cv.DescriptorMatcher.match( queryDescriptors[, masks] )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

参数
queryDescriptors Query set of descriptors.
matches Matches. If a query descriptor is masked out in mask , no match is added for this descriptor. So, matches size may be smaller than the query descriptors count.
masks Set of masks. Each masks[i] specifies permissible matches between the input query descriptors and stored train descriptors from the i-th image trainDescCollection[i].

radiusMatch() [1/2]

void cv::DescriptorMatcher::radiusMatch ( InputArray queryDescriptors ,
InputArray trainDescriptors ,
std::vector< std::vector< DMatch > > & matches ,
float maxDistance ,
InputArray mask = noArray () ,
bool compactResult = false
) const
Python:
matches = cv.DescriptorMatcher.radiusMatch( queryDescriptors, trainDescriptors, maxDistance[, mask[, compactResult]] )
matches = cv.DescriptorMatcher.radiusMatch( queryDescriptors, maxDistance[, masks[, compactResult]] )

For each query descriptor, finds the training descriptors not farther than the specified distance.

参数
queryDescriptors Query set of descriptors.
trainDescriptors Train set of descriptors. This set is not added to the train descriptors collection stored in the class object.
matches Found matches.
compactResult Parameter used when the mask (or masks) is not empty. If compactResult is false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, the matches vector does not contain matches for fully masked-out query descriptors.
maxDistance Threshold for the distance between matched descriptors. Distance means here metric distance (e.g. Hamming distance), not the distance between coordinates (which is measured in Pixels)!
mask Mask specifying permissible matches between an input query and train matrices of descriptors.

For each query descriptor, the methods find such training descriptors that the distance between the query descriptor and the training descriptor is equal or smaller than maxDistance. Found matches are returned in the distance increasing order.

radiusMatch() [2/2]

void cv::DescriptorMatcher::radiusMatch ( InputArray queryDescriptors ,
std::vector< std::vector< DMatch > > & matches ,
float maxDistance ,
InputArrayOfArrays masks = noArray () ,
bool compactResult = false
)
Python:
matches = cv.DescriptorMatcher.radiusMatch( queryDescriptors, trainDescriptors, maxDistance[, mask[, compactResult]] )
matches = cv.DescriptorMatcher.radiusMatch( queryDescriptors, maxDistance[, masks[, compactResult]] )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

参数
queryDescriptors Query set of descriptors.
matches Found matches.
maxDistance Threshold for the distance between matched descriptors. Distance means here metric distance (e.g. Hamming distance), not the distance between coordinates (which is measured in Pixels)!
masks Set of masks. Each masks[i] specifies permissible matches between the input query descriptors and stored train descriptors from the i-th image trainDescCollection[i].
compactResult Parameter used when the mask (or masks) is not empty. If compactResult is false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, the matches vector does not contain matches for fully masked-out query descriptors.

radiusMatchImpl()

virtual void cv::DescriptorMatcher::radiusMatchImpl ( InputArray queryDescriptors ,
std::vector< std::vector< DMatch > > & matches ,
float maxDistance ,
InputArrayOfArrays masks = noArray () ,
bool compactResult = false
)
protected pure virtual

read() [1/2]

void cv::DescriptorMatcher::read ( const 字符串 & fileName )
inline
Python:
None = cv.DescriptorMatcher.read( fileName )
None = cv.DescriptorMatcher.read( arg1 )

read() [2/2]

virtual void cv::DescriptorMatcher::read ( const FileNode & fn )
virtual
Python:
None = cv.DescriptorMatcher.read( fileName )
None = cv.DescriptorMatcher.read( arg1 )

Reads algorithm parameters from a file storage.

Reimplemented from cv::Algorithm .

Reimplemented in cv::FlannBasedMatcher .

train()

virtual void cv::DescriptorMatcher::train ( )
virtual
Python:
None = cv.DescriptorMatcher.train( )

Trains a descriptor matcher.

Trains a descriptor matcher (for example, the flann index). In all methods to match, the method train() is run every time before matching. Some descriptor matchers (for example, BruteForceMatcher) have an empty implementation of this method. Other matchers really train their inner structures (for example, FlannBasedMatcher trains flann::Index ).

Reimplemented in cv::FlannBasedMatcher .

write() [1/3]

void cv::DescriptorMatcher::write ( const 字符串 & fileName ) const
inline
Python:
None = cv.DescriptorMatcher.write( fileName )
None = cv.DescriptorMatcher.write( fs[, name] )

write() [2/3]

virtual void cv::DescriptorMatcher::write ( FileStorage & fs ) const
virtual
Python:
None = cv.DescriptorMatcher.write( fileName )
None = cv.DescriptorMatcher.write( fs[, name] )

Stores algorithm parameters in a file storage.

Reimplemented from cv::Algorithm .

Reimplemented in cv::FlannBasedMatcher .

write() [3/3]

void cv::DescriptorMatcher::write ( const Ptr < FileStorage > & fs ,
const 字符串 & name = 字符串 ()
) const
inline
Python:
None = cv.DescriptorMatcher.write( fileName )
None = cv.DescriptorMatcher.write( fs[, name] )

Member Data Documentation

trainDescCollection

std::vector< Mat > cv::DescriptorMatcher::trainDescCollection
protected

Collection of descriptors from train images.

utrainDescCollection

std::vector< UMat > cv::DescriptorMatcher::utrainDescCollection
protected

The documentation for this class was generated from the following file: