/// <summary>
 /// The grab cut algorithm for segmentation
 /// </summary>
 /// <param name="img">The 8-bit 3-channel image to be segmented</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 one of following values:
 /// 0 (GC_BGD) defines an obvious background pixels.
 /// 1 (GC_FGD) defines an obvious foreground (object) pixel.
 /// 2 (GC_PR_BGR) defines a possible background pixel.
 /// 3 (GC_PR_FGD) defines a possible foreground pixel.
 ///</param>
 /// <param name="rect">The rectangle to initialize the segmentation</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">The number of iterations</param>
 /// <param name="type">The initialization type</param>
 public static void GrabCut(
     IInputArray img,
     IInputOutputArray mask,
     Rectangle rect,
     IInputOutputArray bgdModel,
     IInputOutputArray fgdModel,
     int iterCount,
     CvEnum.GrabcutInitType type)
 {
     using (InputArray iaImg = img.GetInputArray())
         using (InputOutputArray ioaMask = mask == null ? InputOutputArray.GetEmpty() : mask.GetInputOutputArray())
             using (InputOutputArray ioaBgdModel = bgdModel.GetInputOutputArray())
                 using (InputOutputArray ioaFgdModel = fgdModel.GetInputOutputArray())
                     cveGrabCut(iaImg, ioaMask, ref rect, ioaBgdModel, ioaFgdModel, iterCount, type);
 }