class cv::FlannBasedMatcher

Overview

Flann-based descriptor matcher. Moreā€¦

#include <features2d.hpp>

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

    FlannBasedMatcher(
        const Ptr<flann::IndexParams>& indexParams = makePtr<flann::KDTreeIndexParams>(),
        const Ptr<flann::SearchParams>& searchParams = makePtr<flann::SearchParams>()
        );

    // methods

    virtual
    void
    add(InputArrayOfArrays descriptors);

    virtual
    void
    clear();

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

    virtual
    bool
    isMaskSupported() const;

    virtual
    void
    read(const FileNode& fn);

    virtual
    void
    train();

    virtual
    void
    write(FileStorage& fs) const;

    static
    Ptr<FlannBasedMatcher>
    create();

protected:
    // fields

    int addedDescCount;
    Ptr<flann::Index> flannIndex;
    Ptr<flann::IndexParams> indexParams;
    DescriptorCollection mergedDescriptors;
    Ptr<flann::SearchParams> searchParams;

    // methods

    static
    void
    convertToDMatches(
        const DescriptorCollection& descriptors,
        const Mat& indices,
        const Mat& distances,
        std::vector<std::vector<DMatch>>& matches
        );

    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

Flann-based descriptor matcher.

This matcher trains cv::flann::Index on a train descriptor collection and calls its nearest search methods to find the best matches. So, this matcher may be faster when matching a large train collection than the brute force matcher. FlannBasedMatcher does not support masking permissible matches of descriptor sets because flann::Index does not support this. :

Methods

virtual
void
add(InputArrayOfArrays 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.
virtual
void
clear()

Clears the train descriptor collections.

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
read(const FileNode& fn)

Reads algorithm parameters from a file storage.

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

virtual
void
write(FileStorage& fs) const

Stores algorithm parameters in a file storage.

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