【发布时间】:2012-04-23 06:55:35
【问题描述】:
我在一个简单的控制台应用程序(.net 4.0 和 c#)中使用 EmguCV 2.3.0.1416,我对 canny、边缘检测等有疑问。给出以下代码:
var colours = new[]
{
new Bgr(Color.YellowGreen),
new Bgr(Color.Turquoise),
new Bgr(Color.Blue),
new Bgr(Color.DeepPink)
};
// Convert to grayscale, remove noise and get the canny
using (var image = new Image<Bgr, byte>(fileName)
.Convert<Gray, byte>()
.PyrDown()
.PyrUp()
.Canny(new Gray(180),
new Gray(90)))
{
// Save the canny out to a file and then get each contour within
// the canny and get the polygon for it, colour each a different
// colour from a selection so we can easily see if they join up
image.Save(cannyFileName);
var contours = image
.FindContours(CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
RETR_TYPE.CV_RETR_EXTERNAL);
using (var debug = new Image<Bgr, byte>(image.Size))
{
int colIndex = 0;
for (; contours != null; contours = contours.HNext)
{
Contour<Point> poly = contours
.ApproxPoly(contours.Perimeter*0.05,
contours.Storage);
debug.Draw(poly, colours[colIndex], 1);
colIndex++;
if (colIndex > 3) colIndex = 0;
}
debug.Save(debugFileName);
}
}
我得到了这个输出(这实际上只是图像的一部分,但它显示了我在问什么):
如您所见,它有一条带一点粉红色的蓝线,然后是一条绿线。真实的东西在这里只有一个坚实的边缘,所以我希望它是一条线,以便我可以确定它是我所看到的边缘。
原始图像看起来像这样(我已经放大了它,但你可以看到它有一个非常独特的边缘,我希望能够很容易地找到它)。
如果我只看 canny,我可以看到那里的差距,所以我尝试调整创建 canny 的参数(阈值和链接阈值),但它们没有任何区别。
我也扩张然后侵蚀了精明(迭代参数使用相同的值 - 顺便说一下 10),这似乎可以解决问题,但这样做会不会失去准确性(只是感觉有点不对劲)?
那么,我应该如何确保在这种情况下获得单行?
【问题讨论】: