class cv::BFMatcher

Overview

Brute-force descriptor matcher. Moreā€¦

#include <features2d.hpp>

class BFMatcher: public cv::DescriptorMatcher
{
public:
    // construction

    BFMatcher(
        int normType = NORM_L2,
        bool crossCheck = false
        );

    // methods

    virtual
    Ptr<DescriptorMatcher>
    clone(bool emptyTrainData = false) const;

    virtual
    bool
    isMaskSupported() const;

    static
    Ptr<BFMatcher>
    create(
        int normType = NORM_L2,
        bool crossCheck = false
        );

protected:
    // fields

    bool crossCheck;
    int normType;

    // methods

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

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

Inherited Members

public:
    // enums

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

    // classes

    class DescriptorCollection;

    // methods

    virtual
    void
    clear();

    virtual
    bool
    empty() const;

    virtual
    String
    getDefaultName() const;

    virtual
    void
    read(const FileNode& fn);

    virtual
    void
    save(const String& filename) const;

    virtual
    void
    write(FileStorage& fs) const;

    template <typename _Tp>
    static
    Ptr<_Tp>
    load(
        const String& filename,
        const String& objname = String()
        );

    template <typename _Tp>
    static
    Ptr<_Tp>
    loadFromString(
        const String& strModel,
        const String& objname = String()
        );

    template <typename _Tp>
    static
    Ptr<_Tp>
    read(const FileNode& fn);

    virtual
    void
    add(InputArrayOfArrays descriptors);

    virtual
    void
    clear();

    virtual
    Ptr<DescriptorMatcher>
    clone(bool emptyTrainData = false) const = 0;

    virtual
    bool
    empty() const;

    const std::vector<Mat>&
    getTrainDescriptors() const;

    virtual
    bool
    isMaskSupported() const = 0;

    void
    knnMatch(
        InputArray queryDescriptors,
        InputArray trainDescriptors,
        std::vector<std::vector<DMatch>>& matches,
        int k,
        InputArray mask = noArray(),
        bool compactResult = false
        ) const;

    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;

    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;

    void
    radiusMatch(
        InputArray queryDescriptors,
        std::vector<std::vector<DMatch>>& matches,
        float maxDistance,
        InputArrayOfArrays masks = noArray(),
        bool compactResult = false
        );

    void
    read(const String& fileName);

    virtual
    void
    read(const FileNode& fn);

    virtual
    void
    train();

    void
    write(const String& fileName) const;

    virtual
    void
    write(FileStorage& fs) const;

    static
    Ptr<DescriptorMatcher>
    create(const String& descriptorMatcherType);

    static
    Ptr<DescriptorMatcher>
    create(int matcherType);

protected:
    // fields

    std::vector<Mat> trainDescCollection;
    std::vector<UMat> utrainDescCollection;

    // methods

    void
    writeFormat(FileStorage& fs) const;

    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;

    static
    Mat
    clone_op(Mat m);

    static
    bool
    isMaskedOut(
        InputArrayOfArrays masks,
        int queryIdx
        );

    static
    bool
    isPossibleMatch(
        InputArray mask,
        int queryIdx,
        int trainIdx
        );

Detailed Documentation

Brute-force descriptor matcher.

For each descriptor in the first set, this matcher finds the closest descriptor in the second set by trying each one. This descriptor matcher supports masking permissible matches of descriptor sets.

Construction

BFMatcher(
    int normType = NORM_L2,
    bool crossCheck = false
    )

Brute-force matcher constructor (obsolete). Please use BFMatcher.create()

Methods

virtual
Ptr<DescriptorMatcher>
clone(bool emptyTrainData = false) const

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.
virtual
bool
isMaskSupported() const

Returns true if the descriptor matcher supports masking permissible matches.

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

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().