Table of Contents

Method GrabCut

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

GrabCut(InputArray, InputOutputArray, Rect, InputOutputArray, InputOutputArray, int, GrabCutModes)

Segments the image using GrabCut algorithm

public static void GrabCut(InputArray img, InputOutputArray mask, Rect rect, InputOutputArray bgdModel, InputOutputArray fgdModel, int iterCount, GrabCutModes mode)

Parameters

img InputArray

Input 8-bit 3-channel image.

mask InputOutputArray

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 Cv2.GC_BGD / Cv2.GC_FGD / Cv2.GC_PR_BGD / Cv2.GC_PR_FGD

rect 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 InputOutputArray

Temporary array for the background model. Do not modify it while you are processing the same image.

fgdModel InputOutputArray

Temporary arrays for the foreground model. Do not modify it while you are processing the same image.

iterCount int

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 GrabCutModes

Operation mode that could be one of GrabCutFlag value.