BackgroundSubtractorKNN
import { BackgroundSubtractorKNN } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Native object: release it with using or delete(). Factories can return null; check before calling methods. Inherits BackgroundSubtractor.
K-nearest neighbours - based Background/Foreground Segmentation Algorithm.
The class implements the K-nearest neighbours background subtraction described in [Zivkovic2006] . Very efficient if number of foreground pixels is low.
Constructors and members
clone
Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.
clone(): this;The this result.
getHistory
Returns the number of last frames that affect the background model
getHistory(): number;The number result.
setHistory
Sets the number of last frames that affect the background model
setHistory(history: number): void;historyhistory argument (number).
getNSamples
Returns the number of data samples in the background model
getNSamples(): number;The number result.
setNSamples
Sets the number of data samples in the background model.
The model needs to be reinitialized to reserve memory.
setNSamples(_nN: number): void;_nNn n argument (number).
getDist2Threshold
needs reinitialization! 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.
getDist2Threshold(): number;The number result.
setDist2Threshold
Sets the threshold on the squared distance
setDist2Threshold(_dist2Threshold: number): void;_dist2Thresholddist2 threshold argument (number).
getkNNSamples
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.
getkNNSamples(): number;The number result.
setkNNSamples
Sets the k in the kNN. How many nearest neighbours need to match.
setkNNSamples(_nkNN: number): void;_nkNNnk nn argument (number).
getDetectShadows
Returns the shadow detection flag
If true, the algorithm detects shadows and marks them. See createBackgroundSubtractorKNN for
details.
getDetectShadows(): boolean;The boolean result.
setDetectShadows
Enables or disables shadow detection
setDetectShadows(detectShadows: boolean): void;detectShadowsdetect shadows argument (boolean).
getShadowValue
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.
getShadowValue(): number;The number result.
setShadowValue
Sets the shadow value
setShadowValue(value: number): void;valuevalue argument (number).
getShadowThreshold
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.
getShadowThreshold(): number;The number result.
setShadowThreshold
Sets the shadow threshold
setShadowThreshold(threshold: number): void;thresholdthreshold argument (number).
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.