C#上的边缘检测
作者:互联网
我有一个这样的黑白图像(彩色叠加层是我的,可以删除):
我需要弄清楚所显示手的边缘,该怎么做?
我当前的算法:
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.E.,如果我侧手握住我的手,我会得到上指和下指的边缘,仅此而已.
我该怎么做才能纠正这个问题并获得真正的优势?
解决方法:
看一下这样的项目:http://code.google.com/p/aforge/将会对您有很大帮助,而您不必重新发明轮子!
标签:edge-detection,computer-vision,c 来源: https://codeday.me/bug/20191023/1913735.html