org.opencv.features2d

## Class DescriptorMatcher

- java.lang.Object
- - org.opencv.core.Algorithm
  - - org.opencv.features2d.DescriptorMatcher

- Direct Known Subclasses:
    BFMatcher, FlannBasedMatcher

      public class DescriptorMatcher
      extends Algorithm

  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.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `BRUTEFORCE`
    `static int` | `BRUTEFORCE_HAMMING`
    `static int` | `BRUTEFORCE_HAMMINGLUT`
    `static int` | `BRUTEFORCE_L1`
    `static int` | `BRUTEFORCE_SL2`
    `static int` | `FLANNBASED`

    - ### Fields inherited from class org.opencv.core.Algorithm

      `nativeObj`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `DescriptorMatcher(long addr)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static DescriptorMatcher` | `__fromPtr__(long addr)`
    `void` | `add(List<Mat> descriptors)` Adds descriptors to train a CPU(trainDescCollectionis) or GPU(utrainDescCollectionis) descriptor collection.
    `void` | `clear()` Clears the train descriptor collections.
    `DescriptorMatcher` | `clone()` Clones the matcher.
    `DescriptorMatcher` | `clone(boolean emptyTrainData)` Clones the matcher.
    `static DescriptorMatcher` | `create(int matcherType)`
    `static DescriptorMatcher` | `create(String descriptorMatcherType)` Creates a descriptor matcher of a given type with the default parameters (using default constructor).
    `boolean` | `empty()` Returns true if there are no train descriptors in the both collections.
    `protected void` | `finalize()`
    `List<Mat>` | `getTrainDescriptors()` Returns a constant link to the train descriptor collection trainDescCollection .
    `boolean` | `isMaskSupported()` Returns true if the descriptor matcher supports masking permissible matches.
    `void` | `knnMatch(Mat queryDescriptors, List<MatOfDMatch> matches, int k)`
    `void` | `knnMatch(Mat queryDescriptors, List<MatOfDMatch> matches, int k, List<Mat> masks)`
    `void` | `knnMatch(Mat queryDescriptors, List<MatOfDMatch> matches, int k, List<Mat> masks, boolean compactResult)`
    `void` | `knnMatch(Mat queryDescriptors, Mat trainDescriptors, List<MatOfDMatch> matches, int k)` Finds the k best matches for each descriptor from a query set.
    `void` | `knnMatch(Mat queryDescriptors, Mat trainDescriptors, List<MatOfDMatch> matches, int k, Mat mask)` Finds the k best matches for each descriptor from a query set.
    `void` | `knnMatch(Mat queryDescriptors, Mat trainDescriptors, List<MatOfDMatch> matches, int k, Mat mask, boolean compactResult)` Finds the k best matches for each descriptor from a query set.
    `void` | `match(Mat queryDescriptors, Mat trainDescriptors, MatOfDMatch matches)` Finds the best match for each descriptor from a query set.
    `void` | `match(Mat queryDescriptors, Mat trainDescriptors, MatOfDMatch matches, Mat mask)` Finds the best match for each descriptor from a query set.
    `void` | `match(Mat queryDescriptors, MatOfDMatch matches)`
    `void` | `match(Mat queryDescriptors, MatOfDMatch matches, List<Mat> masks)`
    `void` | `radiusMatch(Mat queryDescriptors, List<MatOfDMatch> matches, float maxDistance)`
    `void` | `radiusMatch(Mat queryDescriptors, List<MatOfDMatch> matches, float maxDistance, List<Mat> masks)`
    `void` | `radiusMatch(Mat queryDescriptors, List<MatOfDMatch> matches, float maxDistance, List<Mat> masks, boolean compactResult)`
    `void` | `radiusMatch(Mat queryDescriptors, Mat trainDescriptors, List<MatOfDMatch> matches, float maxDistance)` For each query descriptor, finds the training descriptors not farther than the specified distance.
    `void` | `radiusMatch(Mat queryDescriptors, Mat trainDescriptors, List<MatOfDMatch> matches, float maxDistance, Mat mask)` For each query descriptor, finds the training descriptors not farther than the specified distance.
    `void` | `radiusMatch(Mat queryDescriptors, Mat trainDescriptors, List<MatOfDMatch> matches, float maxDistance, Mat mask, boolean compactResult)` For each query descriptor, finds the training descriptors not farther than the specified distance.
    `void` | `read(String fileName)`
    `void` | `train()` Trains a descriptor matcher Trains a descriptor matcher (for example, the flann index).
    `void` | `write(String fileName)`

    - ### Methods inherited from class org.opencv.core.Algorithm

      `getDefaultName, getNativeObjAddr, save`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### FLANNBASED

          public static final int FLANNBASED

      See Also:
        Constant Field Values

    - #### BRUTEFORCE

          public static final int BRUTEFORCE

      See Also:
        Constant Field Values

    - #### BRUTEFORCE_L1

          public static final int BRUTEFORCE_L1

      See Also:
        Constant Field Values

    - #### BRUTEFORCE_HAMMING

          public static final int BRUTEFORCE_HAMMING

      See Also:
        Constant Field Values

    - #### BRUTEFORCE_HAMMINGLUT

          public static final int BRUTEFORCE_HAMMINGLUT

      See Also:
        Constant Field Values

    - #### BRUTEFORCE_SL2

          public static final int BRUTEFORCE_SL2

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DescriptorMatcher

          protected DescriptorMatcher(long addr)

  - ### Method Detail

    - #### __fromPtr__

          public static DescriptorMatcher __fromPtr__(long addr)

    - #### clone

          public DescriptorMatcher clone(boolean emptyTrainData)

      Clones the matcher.
      Parameters:
        `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:
        automatically generated

    - #### clone

          public DescriptorMatcher clone()

      Clones the matcher. 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.
      Overrides:
        `clone` in class `Object`
      Returns:
        automatically generated

    - #### create

          public static DescriptorMatcher create(String descriptorMatcherType)

      Creates a descriptor matcher of a given type with the default parameters (using default constructor).
      Parameters:
        `descriptorMatcherType` - Descriptor matcher type. Now the following matcher types are supported:
        - `BruteForce` (it uses L2 )
        - `BruteForce-L1`
        - `BruteForce-Hamming`
        - `BruteForce-Hamming(2)`
        - `FlannBased`
      Returns:
        automatically generated

    - #### create

          public static DescriptorMatcher create(int matcherType)

    - #### empty

          public boolean empty()

      Returns true if there are no train descriptors in the both collections.
      Overrides:
        `empty` in class `Algorithm`
      Returns:
        automatically generated

    - #### isMaskSupported

          public boolean isMaskSupported()

      Returns true if the descriptor matcher supports masking permissible matches.
      Returns:
        automatically generated

    - #### getTrainDescriptors

          public List<Mat> getTrainDescriptors()

      Returns a constant link to the train descriptor collection trainDescCollection .
      Returns:
        automatically generated

    - #### add

          public void add(List<Mat> 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.
      Parameters:
        `descriptors` - Descriptors to add. Each descriptors[i] is a set of descriptors from the same train image.

    - #### clear

          public void clear()

      Clears the train descriptor collections.
      Overrides:
        `clear` in class `Algorithm`

    - #### knnMatch

          public void knnMatch(Mat queryDescriptors,
                               Mat trainDescriptors,
                               List<MatOfDMatch> matches,
                               int k,
                               Mat mask,
                               boolean compactResult)

      Finds the k best matches for each descriptor from a query set.
      Parameters:
        `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

          public void knnMatch(Mat queryDescriptors,
                               Mat trainDescriptors,
                               List<MatOfDMatch> matches,
                               int k,
                               Mat mask)

      Finds the k best matches for each descriptor from a query set.
      Parameters:
        `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. 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

          public void knnMatch(Mat queryDescriptors,
                               Mat trainDescriptors,
                               List<MatOfDMatch> matches,
                               int k)

      Finds the k best matches for each descriptor from a query set.
      Parameters:
        `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. 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. 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

          public void knnMatch(Mat queryDescriptors,
                               List<MatOfDMatch> matches,
                               int k,
                               List<Mat> masks,
                               boolean compactResult)

      Parameters:
        `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.

    - #### knnMatch

          public void knnMatch(Mat queryDescriptors,
                               List<MatOfDMatch> matches,
                               int k,
                               List<Mat> masks)

      Parameters:
        `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]. 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.

    - #### knnMatch

          public void knnMatch(Mat queryDescriptors,
                               List<MatOfDMatch> matches,
                               int k)

      Parameters:
        `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. descriptors and stored train descriptors from the i-th image trainDescCollection[i]. 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.

    - #### match

          public void match(Mat queryDescriptors,
                            Mat trainDescriptors,
                            MatOfDMatch matches,
                            Mat mask)

      Finds the best match for each descriptor from a query set.
      Parameters:
        `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

          public void match(Mat queryDescriptors,
                            Mat trainDescriptors,
                            MatOfDMatch matches)

      Finds the best match for each descriptor from a query set.
      Parameters:
        `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. 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

          public void match(Mat queryDescriptors,
                            MatOfDMatch matches,
                            List<Mat> masks)

      Parameters:
        `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].

    - #### match

          public void match(Mat queryDescriptors,
                            MatOfDMatch matches)

      Parameters:
        `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. descriptors and stored train descriptors from the i-th image trainDescCollection[i].

    - #### radiusMatch

          public void radiusMatch(Mat queryDescriptors,
                                  Mat trainDescriptors,
                                  List<MatOfDMatch> matches,
                                  float maxDistance,
                                  Mat mask,
                                  boolean compactResult)

      For each query descriptor, finds the training descriptors not farther than the specified distance.
      Parameters:
        `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

          public void radiusMatch(Mat queryDescriptors,
                                  Mat trainDescriptors,
                                  List<MatOfDMatch> matches,
                                  float maxDistance,
                                  Mat mask)

      For each query descriptor, finds the training descriptors not farther than the specified distance.
      Parameters:
        `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. 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

          public void radiusMatch(Mat queryDescriptors,
                                  Mat trainDescriptors,
                                  List<MatOfDMatch> matches,
                                  float maxDistance)

      For each query descriptor, finds the training descriptors not farther than the specified distance.
      Parameters:
        `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. 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)! 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

          public void radiusMatch(Mat queryDescriptors,
                                  List<MatOfDMatch> matches,
                                  float maxDistance,
                                  List<Mat> masks,
                                  boolean compactResult)

      Parameters:
        `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.

    - #### radiusMatch

          public void radiusMatch(Mat queryDescriptors,
                                  List<MatOfDMatch> matches,
                                  float maxDistance,
                                  List<Mat> masks)

      Parameters:
        `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]. 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

          public void radiusMatch(Mat queryDescriptors,
                                  List<MatOfDMatch> matches,
                                  float maxDistance)

      Parameters:
        `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)! descriptors and stored train descriptors from the i-th image trainDescCollection[i]. 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.

    - #### read

          public void read(String fileName)

    - #### train

          public void 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 ).

    - #### write

          public void write(String fileName)

    - #### finalize

          protected void finalize()
                           throws Throwable

      Overrides:
        `finalize` in class `Algorithm`
      Throws:
        `Throwable`

Generated on Thu Jul 25 2019 21:39:44 UTC / OpenCV 3.4.7