Skip to content

BackgroundSubtractor

Motion and trackingclassOpenCV 5.0.0
import { BackgroundSubtractor } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTSConstructor or factory
CLASSBackgroundSubtractor
RETURN TYPEOwned native handle
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Native object: release it with using or delete(). Factories can return null; check before calling methods. Inherits Algorithm.

Base class for background/foreground segmentation. :

The class is only used to define the common interface for the whole family of background/foreground segmentation algorithms.

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;
Returns

The this result.

apply

Computes a foreground mask.

apply(image: Mat, fgmask: Mat, learningRate: number): void;
2 available overloads
apply(image: Mat, fgmask: Mat): void;
apply(image: Mat, fgmask: Mat, learningRate: number): void;
image

Next video frame.

fgmask

Output destination, filled by the native operation. The output foreground mask as an 8-bit binary image.

learningRate

The value between 0 and 1 that indicates how fast the background model is learnt. Negative parameter value makes the algorithm to use some automatically chosen learning rate. 0 means that the background model is not updated at all, 1 means that the background model is completely reinitialized from the last frame.

apply1

Computes a foreground mask with known foreground mask input.

Note: This method has a default virtual implementation that throws a "not impemented" error. Foreground masking may not be supported by all background subtractors.

apply1(image: Mat, knownForegroundMask: Mat, fgmask: Mat, learningRate: number): void;
2 available overloads
apply1(image: Mat, knownForegroundMask: Mat, fgmask: Mat): void;
apply1(image: Mat, knownForegroundMask: Mat, fgmask: Mat, learningRate: number): void;
image

Next video frame. Floating point frame will be used without scaling and should be in range [0,255].

knownForegroundMask

The mask for inputting already known foreground, allows model to ignore pixels.

fgmask

Output destination, filled by the native operation. The output foreground mask as an 8-bit binary image.

learningRate

The value between 0 and 1 that indicates how fast the background model is learnt. Negative parameter value makes the algorithm to use some automatically chosen learning rate. 0 means that the background model is not updated at all, 1 means that the background model is completely reinitialized from the last frame.

getBackgroundImage

Computes a background image.

Note: Sometimes the background image can be very blurry, as it contain the average background statistics.

getBackgroundImage(backgroundImage: Mat): void;
backgroundImage

Output destination, filled by the native operation. The output background image.

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.