Skip to content

grabCut

Image processingfunctionOpenCV 5.0.0
import { grabCut } from '@banou/opencv-wasm'

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

example: samples/cpp/grabcut.cpp An example using the GrabCut algorithm Sample Screenshot Runs the GrabCut algorithm.

The function implements the GrabCut image segmentation algorithm.

grabCut(img: Mat, mask: Mat, rect: Rect, bgdModel: Mat, fgdModel: Mat, iterCount: number, mode: number): void;
2 available overloads
grabCut(img: Mat, mask: Mat, rect: Rect, bgdModel: Mat, fgdModel: Mat, iterCount: number): void;
grabCut(img: Mat, mask: Mat, rect: Rect, bgdModel: Mat, fgdModel: Mat, iterCount: number, mode: number): void;
img

Input 8-bit 3-channel image.

mask

Input/output value, modified by the native operation. Input/output 8-bit single-channel mask. The mask is initialized by the function when mode is set to #GC_INIT_WITH_RECT. Its elements may have one of the #GrabCutClasses.

rect

ROI containing a segmented object. The pixels outside of the ROI are marked as "obvious background". The parameter is only used when mode==#GC_INIT_WITH_RECT .

bgdModel

Input/output value, modified by the native operation. Temporary array for the background model. Do not modify it while you are processing the same image.

fgdModel

Input/output value, modified by the native operation. Temporary arrays for the foreground model. Do not modify it while you are processing the same image.

iterCount

Number of iterations the algorithm should make before returning the result. Note that the result can be refined with further calls with mode==#GC_INIT_WITH_MASK or mode==GC_EVAL .

mode

Operation mode that could be one of the #GrabCutModes

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.