gpt4 book ai didi

c# - Emgu/Opencv 中的连通分量标记

转载 作者:太空宇宙 更新时间:2023-11-03 21:46:41 27 4
gpt4 key购买 nike

我一直在寻找一种在 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;
}

最佳答案

我会使用以下内容:

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

关于c# - Emgu/Opencv 中的连通分量标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22301008/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com