OpenCvSharp.Cv2.FindContoursAsMat C# (CSharp) Method

FindContoursAsMat() public static method

Finds contours in a binary image.
public static FindContoursAsMat ( InputOutputArray image, RetrievalModes mode, ContourApproximationModes method, Point offset = null ) : MatOfPoint[]
image InputOutputArray Source, an 8-bit single-channel image. Non-zero pixels are treated as 1’s. /// Zero pixels remain 0’s, so the image is treated as binary. /// The function modifies the image while extracting the contours.
mode RetrievalModes Contour retrieval mode
method ContourApproximationModes Contour approximation method
offset Point Optional offset by which every contour point is shifted. /// This is useful if the contours are extracted from the image ROI and then they should be analyzed in the whole image context.
return MatOfPoint[]
        public static MatOfPoint[] FindContoursAsMat(InputOutputArray image,
            RetrievalModes mode, ContourApproximationModes method, Point? offset = null)
        {
            if (image == null)
                throw new ArgumentNullException(nameof(image));
            image.ThrowIfNotReady();

            Point offset0 = offset.GetValueOrDefault(new Point());
            IntPtr contoursPtr;
            NativeMethods.imgproc_findContours2_OutputArray(image.CvPtr, out contoursPtr, (int)mode, (int)method, offset0);
            image.Fix();

            using (var contoursVec = new VectorOfMat(contoursPtr))
            {
                return contoursVec.ToArray<MatOfPoint>();
            }
        }
        #endregion
Cv2