边缘检测在C# [英] Edge detection on C#
问题描述
我有一个黑白图片(颜色覆盖是我的,可以删除):
我需要弄清楚显示的手的边缘,我该怎么做?
I have a black and white image like this (color overlays are mine, and can be removed): I need to figure out the edge of the hand shown, how can I do that?
我当前的算法: / p>
My current algorithm:
List<Point> edgePoints = new List<Point>();
for (int x = 0; x < largest.Rectangle.Width && edgePoints.Count == 0; x++) {
//top
for (int y = 0; y < largest.Rectangle.Height - 3 && edgePoints.Count == 0; y++) {
if (colorGrid[x, y].ToArgb() == Color.White.ToArgb() &&
colorGrid[x, y + 1].ToArgb() == Color.White.ToArgb() &&
colorGrid[x, y + 2].ToArgb() == Color.White.ToArgb() &&
colorGrid[x, y + 3].ToArgb() == Color.White.ToArgb()
) {
edgePoints.Add(new Point(x, y));
//g.DrawLine(new System.Drawing.Pen(Color.Orange), new Point(largest.Rectangle.X + x, largest.Rectangle.Y + y), new Point(largest.Rectangle.X + x, largest.Rectangle.Y + y + 3));
break;
}
}
//bottom
for (int y = largest.Rectangle.Height - 1; y > 3 && edgePoints.Count == 0; y++) {
if (colorGrid[x, y].ToArgb() == Color.White.ToArgb() &&
colorGrid[x, y - 1].ToArgb() == Color.White.ToArgb() &&
colorGrid[x, y - 2].ToArgb() == Color.White.ToArgb() &&
colorGrid[x, y - 3].ToArgb() == Color.White.ToArgb()
) {
edgePoints.Add(new Point(x, y));
//g.DrawLine(new System.Drawing.Pen(Color.Orange), new Point(largest.Rectangle.X + x, largest.Rectangle.Y + y), new Point(largest.Rectangle.X + x, largest.Rectangle.Y + y + 3));
break;
}
}
}
轮廓,但如果和曲线在任何地方,该边缘不被检测。 IE,如果我握着我的手,我会得到顶部手指和底部手指的边缘,但这是它的。
Results in a fairly well defined outline, but if the and curves in anywhere, that edge is not detected. I.E., if I held my hand sideways, I'd get the edge of the top finger and bottom finger, but that's it.
我可以做什么来纠正这个和找到一个真正的边缘?
What can I do to correct this and get a real edge?
推荐答案
看看这样的项目: http://code.google.com/p/aforge/ ,这将帮助你很多,你不必重新发明轮子!
Have a look on projects like this: http://code.google.com/p/aforge/ that will help you a lot and you dont have to reinvent the wheel!
这篇关于边缘检测在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!