繁体   English   中英

遍历轮廓-OpenCV(C#)

[英]Iterate through Contours - OpenCV ( C# )

我正在尝试使用OpenCV(C#)中的ContourArea()方法获取轮廓的面积。 在每次迭代中,它总是为Area返回相同的值。
这是我的守则的相关部分。

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;

    }
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM