我使用EmguCV 2.3.0.1416从一个简单的控制台应用程序(.NET 4.0和C#)和我身边有一个问题,精明的,边缘检测等考虑下面的代码:如何使用EmguCV获得连续的多边形?
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(使用相同的值的迭代参数 - 10顺便说一句),似乎做的伎俩,但我可以失去准确性这样做(它只是觉得有点错了)?
那么,我应该如何确保在这种情况下我得到一条线呢?
你的意思是调用SmoothMedian方法(有几个)?我刚刚尝试过,但没有任何区别。 – kmp 2012-05-02 11:31:07
@kmp那么,你可以做二进制阈值?如果它不影响你的目的,请使用它。也许图像的模糊边缘正在造成它。 – batbaatar 2012-05-02 11:59:41
有一个ThresholdBinary方法需要两个参数:http://www.emgu.com/wiki/files/2.0.0.0/html/046038a6-4e0e-ba4c-d01f-eb3fc1c29383.htm - 我会为这些做些什么值?而且,这样做会不会影响找到边缘的准确性? – kmp 2012-05-02 12:18:18