遍历轮廓 - OpenCV ( C# )

Iterate through Contours - OpenCV ( C# )

我正在尝试使用 OpenCV (C#) 中的 ContourArea() 方法获取等高线的面积。在每次迭代中,它总是 returns 相同的区域值。
这是我的代码的相关部分。

public void getcontour()
    {
        IplImage binary_image= Cv.LoadImage("binary.png", LoadMode.GrayScale);
        CvMemStorage memory = new CvMemStorage();
        OpenCvSharp.CvSeq<CvPoint> contours;

        Cv.FindContours(binary_image, memory, out contours);
        double area=0;

        for (int k=0; k<=contours.Total;k++)
        {
            area= contours.ContourArea();
            /*need to access properties such as width & height of current contour in here*/
        }

        //draw contours
        IplImage save = Cv.CreateImage(binary_image.Size, BitDepth.U8, 1);
        Cv.DrawContours(save, contours, col1, col2, 1, 1);
        Cv.SaveImage("cont.png", save);

    }

找到了用 OpenCv (C#)
遍历 contours 的解决方案 这是代码。

public void getcontour()
{
    IplImage binary_image= Cv.LoadImage("binary.png", LoadMode.GrayScale);
    CvMemStorage memory = new CvMemStorage();
    OpenCvSharp.CvSeq<CvPoint> contours;

    Cv.FindContours(binary_image, memory, out contours);
    double area=0;

    while (contours != null) 
    {
        area = contours.ContourArea();
        /* logic */
        contours = contours.HNext;

    }
 }