Skip to content

DescriptorMatcher

Features and matchingclassOpenCV 5.0.0
import { DescriptorMatcher } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

Native object: release it with using or delete(). Factories can return null; check before calling methods. Inherits Algorithm.

features_main
DescriptorMatcher * ***************************************************************************************

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.

Constructors and members

static create

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

create(descriptorMatcherType: EmbindString): DescriptorMatcher | null;
descriptorMatcherType

Descriptor matcher type. Now the following matcher types are supported:

  • BruteForce (it uses L2 )
  • BruteForce-L1
  • BruteForce-Hamming
  • BruteForce-Hamming(2)
  • FlannBased
Returns

The DescriptorMatcher | null result.

static create1

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

create1(matcherType: number): DescriptorMatcher | null;
matcherType

matcher type argument (number).

Returns

The DescriptorMatcher | null result.

add

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.
add(descriptors: MatVector): void;
descriptors

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

getTrainDescriptors

Returns a constant link to the train descriptor collection trainDescCollection .

getTrainDescriptors(): MatVector;
Returns

The MatVector result. Release returned native handles with using or delete(), including handles nested in results.

clear

Clears the train descriptor collections.

clear(): void;

empty

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

empty(): boolean;
Returns

The boolean result.

isMaskSupported

Returns true if the descriptor matcher supports masking permissible matches.

isMaskSupported(): boolean;
Returns

The boolean result.

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 ).
train(): void;

match

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

match(queryDescriptors: Mat, trainDescriptors: Mat, matches: DMatchVector, mask: Mat): void;
2 available overloads
match(queryDescriptors: Mat, trainDescriptors: Mat, matches: DMatchVector): void;
match(queryDescriptors: Mat, trainDescriptors: Mat, matches: DMatchVector, mask: Mat): void;
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

Output destination, filled by the native operation. 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.

match1

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

match1(queryDescriptors: Mat, matches: DMatchVector, masks: MatVector): void;
2 available overloads
match1(queryDescriptors: Mat, matches: DMatchVector): void;
match1(queryDescriptors: Mat, matches: DMatchVector, masks: MatVector): void;
queryDescriptors

Query set of descriptors.

matches

Output destination, filled by the native operation. 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].

knnMatch

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

knnMatch(queryDescriptors: Mat, trainDescriptors: Mat, matches: DMatchVectorVector, k: number, mask: Mat, compactResult: boolean): void;
3 available overloads
knnMatch(queryDescriptors: Mat, trainDescriptors: Mat, matches: DMatchVectorVector, k: number): void;
knnMatch(queryDescriptors: Mat, trainDescriptors: Mat, matches: DMatchVectorVector, k: number, mask: Mat): void;
knnMatch(queryDescriptors: Mat, trainDescriptors: Mat, matches: DMatchVectorVector, k: number, mask: Mat, compactResult: boolean): void;
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

Output destination, filled by the native operation. 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.

mask

Mask specifying permissible matches between an input query and train matrices of descriptors.

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.

knnMatch1

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

knnMatch1(queryDescriptors: Mat, matches: DMatchVectorVector, k: number, masks: MatVector, compactResult: boolean): void;
3 available overloads
knnMatch1(queryDescriptors: Mat, matches: DMatchVectorVector, k: number): void;
knnMatch1(queryDescriptors: Mat, matches: DMatchVectorVector, k: number, masks: MatVector): void;
knnMatch1(queryDescriptors: Mat, matches: DMatchVectorVector, k: number, masks: MatVector, compactResult: boolean): void;
queryDescriptors

Query set of descriptors.

matches

Output destination, filled by the native operation. 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.

radiusMatch

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

radiusMatch(queryDescriptors: Mat, trainDescriptors: Mat, matches: DMatchVectorVector, maxDistance: number, mask: Mat, compactResult: boolean): void;
3 available overloads
radiusMatch(queryDescriptors: Mat, trainDescriptors: Mat, matches: DMatchVectorVector, maxDistance: number): void;
radiusMatch(queryDescriptors: Mat, trainDescriptors: Mat, matches: DMatchVectorVector, maxDistance: number, mask: Mat): void;
radiusMatch(queryDescriptors: Mat, trainDescriptors: Mat, matches: DMatchVectorVector, maxDistance: number, mask: Mat, compactResult: boolean): void;
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

Output destination, filled by the native operation. 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)!

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.

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.

radiusMatch1

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

radiusMatch1(queryDescriptors: Mat, matches: DMatchVectorVector, maxDistance: number, masks: MatVector, compactResult: boolean): void;
3 available overloads
radiusMatch1(queryDescriptors: Mat, matches: DMatchVectorVector, maxDistance: number): void;
radiusMatch1(queryDescriptors: Mat, matches: DMatchVectorVector, maxDistance: number, masks: MatVector): void;
radiusMatch1(queryDescriptors: Mat, matches: DMatchVectorVector, maxDistance: number, masks: MatVector, compactResult: boolean): void;
queryDescriptors

Query set of descriptors.

matches

Output destination, filled by the native operation. 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.

write

Writes matcher object to a file storage

write(fileName: EmbindString): void;
fileName

file name argument (EmbindString).

write1

see corresponding cv::Algorithm method

write1(fs: FileStorage, name: EmbindString): void;
fs

fs argument (FileStorage).

name

name argument (EmbindString).

read

Reads matcher object from a file node see corresponding cv::Algorithm method

read(fileName: EmbindString): void;
fileName

file name argument (EmbindString).

read1

Reads matcher object from a file node see corresponding cv::Algorithm method

read1(arg1: FileNode): void;
arg1

arg1 argument (FileNode).

clone

Clones the matcher.

clone(emptyTrainData: boolean): DescriptorMatcher | null;
2 available overloads
clone(): DescriptorMatcher | null;
clone(emptyTrainData: boolean): DescriptorMatcher | null;
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.

Returns

The DescriptorMatcher | null result.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.