[EmguCV] FindContours

   /// <summary>
        /// Retrieves contours from the binary image and returns the number of retrieved contours. The pointer firstContour is filled by the function. It will contain pointer to the first most outer contour or IntPtr.Zero if no contours is detected (if the image is completely black). Other contours may be reached from firstContour using h_next and v_next links. The sample in cvDrawContours discussion shows how to use contours for connected component detection. Contours can be also used for shape analysis and object recognition - see squares.c in OpenCV sample directory
        /// The function modifies the source image content
        /// </summary>
        /// <param name="image">The source 8-bit single channel image. Non-zero pixels are treated as 1s, zero pixels remain 0s - that is image treated as binary. To get such a binary image from grayscale, one may use cvThreshold, cvAdaptiveThreshold or cvCanny. The function modifies the source image content</param>
        /// <param name="contours">Detected contours. Each contour is stored as a vector of points.</param>
        /// <param name="hierarchy">Optional output vector, containing information about the image topology.</param>
        /// <param name="mode">Retrieval mode</param>
        /// <param name="method">Approximation method (for all the modes, except CV_RETR_RUNS, which uses built-in approximation). </param>
        /// <param name="offset">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</param>
        /// <returns>The number of countours</returns>
        public static void FindContours(
           IInputOutputArray image, IOutputArray contours, IOutputArray hierarchy,
           CvEnum.RetrType mode,
           CvEnum.ChainApproxMethod method,
           Point offset = new Point())
        {
            using (InputOutputArray ioaImage = image.GetInputOutputArray())
            using (OutputArray oaContours = contours.GetOutputArray())
            using (OutputArray oaHierarchy = hierarchy == null ? OutputArray.GetEmpty() : hierarchy.GetOutputArray())
                cveFindContours(ioaImage, oaContours, oaHierarchy, mode, method, ref offset);
        }





  /// <summary>
    /// contour retrieval mode
    /// </summary>
    public enum RetrType
    {
        /// <summary>
        /// retrieve only the extreme outer contours 
        /// </summary>
        External = 0,
        /// <summary>
        ///  retrieve all the contours and puts them in the list 
        /// </summary>
        List = 1,
        /// <summary>
        /// retrieve all the contours and organizes them into two-level hierarchy: top level are external boundaries of the components, second level are bounda boundaries of the holes 
        /// </summary>
        Ccomp = 2,
        /// <summary>
        /// retrieve all the contours and reconstructs the full hierarchy of nested contours 
        /// </summary>
        Tree = 3
    }





  /// <summary>
    /// contour approximation method
    /// </summary>
    public enum ChainApproxMethod : int
    {
        /// <summary>
        /// output contours in the Freeman chain code. All other methods output polygons (sequences of vertices). 
        /// </summary>
        ChainCode = 0,
        /// <summary>
        /// translate all the points from the chain code into points;
        /// </summary>
        ChainApproxNone = 1,
        /// <summary>
        /// compress horizontal, vertical, and diagonal segments, that is, the function leaves only their ending points; 
        /// </summary>
        ChainApproxSimple = 2,
        /// <summary>
        /// 
        /// </summary>
        ChainApproxTc89L1 = 3,
        /// <summary>
        /// apply one of the flavors of Teh-Chin chain approximation algorithm
        /// </summary>
        ChainApproxTc89Kcos = 4,
        /// <summary>
        /// use completely different contour retrieval algorithm via linking of horizontal segments of 1s. Only LIST retrieval mode can be used with this method
        /// </summary>
        LinkRuns = 5
    }

猜你喜欢

转载自blog.csdn.net/zxcvb036/article/details/81077608