【发布时间】:2014-04-13 14:32:29
【问题描述】:
我一直在寻找一种在 Emgu(OpenCV 的 c# 包装器)中标记连接组件的方法。我没有找到一种直接的方法来实现这种基本的 CV 策略。但是,我确实遇到了许多使用 FindContours 和 DrawContours 但没有代码示例的建议。所以我试了一下,它似乎工作正常。
我把它放在这里有两个原因。
- 所以搜索它的人可以找到代码示例。
- 更重要的是,我想知道是否有优化和改进此功能的建议。例如。 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