[英]Connected component labeling in Emgu / Opencv
我一直在寻找Emgu(OpenCV的c#包装器)中用于连接组件标签的方法。 我没有找到这种基本的简历策略的直接方法。 但是,我确实遇到了很多使用FindContours和DrawContours的建议,但是没有代码示例。 因此,我尝试了一下,看来效果还不错。
我将其放在此处的原因有两个。
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)的实现以组合附近区域。
PS:是有效/合适的FindContours的链近似方法
如果您使用的是NO_APPROX,则不会使用链式代码的近似值。 通过使用此功能,可以得到不平滑的边缘(具有许多小的丘陵和山谷),但是如果这样不打扰您,则此参数值还可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.