class cv::BackgroundSubtractorKNN

Overview

K-nearest neigbours - based Background/Foreground Segmentation Algorithm. More…

#include <background_segm.hpp>

class BackgroundSubtractorKNN: public cv::BackgroundSubtractor
{
public:
    // methods

    virtual
    bool
    getDetectShadows() const = 0;

    virtual
    double
    getDist2Threshold() const = 0;

    virtual
    int
    getHistory() const = 0;

    virtual
    int
    getkNNSamples() const = 0;

    virtual
    int
    getNSamples() const = 0;

    virtual
    double
    getShadowThreshold() const = 0;

    virtual
    int
    getShadowValue() const = 0;

    virtual
    void
    setDetectShadows(bool detectShadows) = 0;

    virtual
    void
    setDist2Threshold(double _dist2Threshold) = 0;

    virtual
    void
    setHistory(int history) = 0;

    virtual
    void
    setkNNSamples(int _nkNN) = 0;

    virtual
    void
    setNSamples(int _nN) = 0;

    virtual
    void
    setShadowThreshold(double threshold) = 0;

    virtual
    void
    setShadowValue(int value) = 0;
};

Inherited Members

public:
    // 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
    apply(
        InputArray image,
        OutputArray fgmask,
        double learningRate = -1
        ) = 0;

    virtual
    void
    getBackgroundImage(OutputArray backgroundImage) const = 0;

protected:
    // methods

    void
    writeFormat(FileStorage& fs) const;

Detailed Documentation

K-nearest neigbours - based Background/Foreground Segmentation Algorithm.

The class implements the K-nearest neigbours background subtraction described in [97]. Very efficient if number of foreground pixels is low.

Methods

virtual
bool
getDetectShadows() const = 0

Returns the shadow detection flag.

If true, the algorithm detects shadows and marks them. See createBackgroundSubtractorKNN for details.

virtual
double
getDist2Threshold() const = 0

Returns the threshold on the squared distance between the pixel and the sample.

The threshold on the squared distance between the pixel and the sample to decide whether a pixel is close to a data sample.

virtual
int
getHistory() const = 0

Returns the number of last frames that affect the background model.

virtual
int
getkNNSamples() const = 0

Returns the number of neighbours, the k in the kNN.

K is the number of samples that need to be within dist2Threshold in order to decide that that pixel is matching the kNN background model.

virtual
int
getNSamples() const = 0

Returns the number of data samples in the background model.

virtual
double
getShadowThreshold() const = 0

Returns the shadow threshold.

A shadow is detected if pixel is a darker version of the background. The shadow threshold (Tau in the paper) is a threshold defining how much darker the shadow can be. Tau= 0.5 means that if a pixel is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiara, Detecting Moving Shadows…*, IEEE PAMI,2003.

virtual
int
getShadowValue() const = 0

Returns the shadow value.

Shadow value is the value used to mark shadows in the foreground mask. Default value is 127. Value 0 in the mask always means background, 255 means foreground.

virtual
void
setDetectShadows(bool detectShadows) = 0

Enables or disables shadow detection.

virtual
void
setDist2Threshold(double _dist2Threshold) = 0

Sets the threshold on the squared distance.

virtual
void
setHistory(int history) = 0

Sets the number of last frames that affect the background model.

virtual
void
setkNNSamples(int _nkNN) = 0

Sets the k in the kNN. How many nearest neigbours need to match.

virtual
void
setNSamples(int _nN) = 0

Sets the number of data samples in the background model.

The model needs to be reinitalized to reserve memory.

virtual
void
setShadowThreshold(double threshold) = 0

Sets the shadow threshold.

virtual
void
setShadowValue(int value) = 0

Sets the shadow value.