/// <summary> /// Segments the image using GrabCut algorithm. /// The input is 8-bit 3-channel image. /// </summary> /// <param name="mask">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</param> /// <param name="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.</param> /// <param name="bgdModel">Temporary array for the background model. Do not modify it while you are processing the same image.</param> /// <param name="fgdModel">Temporary arrays for the foreground model. Do not modify it while you are processing the same image.</param> /// <param name="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 .</param> /// <param name="mode">Operation mode that could be one of GrabCutFlag value.</param> public void GrabCut(InputOutputArray mask, Rect rect, InputOutputArray bgdModel, InputOutputArray fgdModel, int iterCount, GrabCutFlag mode) { Cv2.GrabCut(this, mask, rect, bgdModel, fgdModel, iterCount, mode); }
/// <summary> /// Segments the image using GrabCut algorithm /// </summary> /// <param name="img">Input 8-bit 3-channel image.</param> /// <param name="mask">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</param> /// <param name="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.</param> /// <param name="bgdModel">Temporary array for the background model. Do not modify it while you are processing the same image.</param> /// <param name="fgdModel">Temporary arrays for the foreground model. Do not modify it while you are processing the same image.</param> /// <param name="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 .</param> /// <param name="mode">Operation mode that could be one of GrabCutFlag value.</param> public static void GrabCut(InputArray img, InputOutputArray mask, Rect rect, InputOutputArray bgdModel, InputOutputArray fgdModel, int iterCount, GrabCutFlag mode) { if (img == null) throw new ArgumentNullException("img"); if (mask == null) throw new ArgumentNullException("mask"); if (bgdModel == null) throw new ArgumentNullException("bgdModel"); if (fgdModel == null) throw new ArgumentNullException("fgdModel"); img.ThrowIfDisposed(); mask.ThrowIfNotReady(); bgdModel.ThrowIfNotReady(); fgdModel.ThrowIfNotReady(); NativeMethods.imgproc_grabCut(img.CvPtr, mask.CvPtr, rect, bgdModel.CvPtr, fgdModel.CvPtr, iterCount, (int)mode); mask.Fix(); bgdModel.Fix(); fgdModel.Fix(); }