【问题标题】:Connected component labeling in Emgu / OpencvEmgu / Opencv中的连接组件标签
【发布时间】:2014-04-13 14:32:29
【问题描述】:

我一直在寻找一种在 Emgu(OpenCV 的 c# 包装器)中标记连接组件的方法。我没有找到一种直接的方法来实现这种基本的 CV 策略。但是,我确实遇到了许多使用 FindContours 和 DrawContours 但没有代码示例的建议。所以我试了一下,它似乎工作正常。

我把它放在这里有两个原因。

  1. 所以搜索它的人可以找到代码示例。
  2. 更重要的是,我想知道是否有优化和改进此功能的建议。例如。 FindContours 的链近似方法是否有效/合适?
    public static Image<Gray, byte> LabelConnectedComponents(this Image<Gray, byte> binary, int startLabel)
    {
        Contour<Point> contours = binary.FindContours(
            CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE, 
            RETR_TYPE.CV_RETR_CCOMP);

        int count = startLabel;
        for (Contour<Point> cont = contours;
                    cont != null;
                    cont = cont.HNext)
        {
            CvInvoke.cvDrawContours(
            binary,
            cont,
            new MCvScalar(count),
            new MCvScalar(0),
            2,
            -1,
            LINE_TYPE.FOUR_CONNECTED,
            new Point(0, 0));
            ++count;
        }
        return binary;
    }

【问题讨论】:

    标签: c# opencv computer-vision emgucv


    【解决方案1】:

    我会使用以下内容:

       connected component labeling (AForge / Accord.NET ?)
       (although for many cases you will find it almost the same for the function that you wrote, give it a try to verify the results)
    

    完成此步骤后,您可能会发现更多区域靠近且属于同一个人。 比你可以使用: 实施或搜索实施分层凝聚聚类 (HCA) 合并关闭区域。

    附: FindContours 的链式逼近方法是否有效/合适

    如果您使用的是 NO_APPROX,则不会使用链码的近似值。通过使用它,您可以获得不平滑的边缘(有许多小山丘和山谷),但如果这不会打扰您,那么这个参数值就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-07
      • 2018-03-08
      • 2011-01-10
      • 2014-05-19
      • 2011-07-31
      • 2012-09-23
      相关资源
      最近更新 更多