Table of Contents

Class BackgroundSubtractorKNN

Namespace
Emgu.CV
Assembly
Emgu.CV.dll

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

public class BackgroundSubtractorKNN : UnmanagedObject, IDisposable, IBackgroundSubtractor, IAlgorithm
Inheritance
BackgroundSubtractorKNN
Implements
Inherited Members
Extension Methods

Constructors

BackgroundSubtractorKNN(int, double, bool)

Create a K-nearest neighbors - based Background/Foreground Segmentation Algorithm.

public BackgroundSubtractorKNN(int history, double dist2Threshold, bool detectShadows)

Parameters

history int

Length of the history.

dist2Threshold double

Threshold on the squared distance between the pixel and the sample to decide whether a pixel is close to that sample. This parameter does not affect the background update.

detectShadows bool

If true, the algorithm will detect shadows and mark them. It decreases the speed a bit, so if you do not need this feature, set the parameter to false.

Properties

AlgorithmPtr

Pointer to the unmanaged Algorithm object

public nint AlgorithmPtr { get; }

Property Value

nint

BackgroundSubtractorPtr

Pointer to the unmanaged BackgroundSubtractor object

public nint BackgroundSubtractorPtr { get; }

Property Value

nint

DetectShadows

If true, the algorithm detects shadows and marks them.

public bool DetectShadows { get; set; }

Property Value

bool

Dist2Threshold

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

public double Dist2Threshold { get; set; }

Property Value

double

History

The number of last frames that affect the background model

public int History { get; set; }

Property Value

int

KNNSamples

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 pixel is matching the kNN background model.

public int KNNSamples { get; set; }

Property Value

int

NSamples

The number of data samples in the background model

public int NSamples { get; set; }

Property Value

int

ShadowThreshold

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.

public double ShadowThreshold { get; set; }

Property Value

double

ShadowValue

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.

public int ShadowValue { get; set; }

Property Value

int

Methods

DisposeObject()

Release all the unmanaged memory associated with this background model.

protected override void DisposeObject()