C# 上的边缘检测

发布于 2024-10-15 19:22:37 字数 1990 浏览 2 评论 0原文

我有一个像这样的黑白图像(颜色叠加是我的,可以删除): 在此处输入图像描述 我需要找出所示手的边缘,我该怎么做?

我当前的算法:

        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;
                }
            }
        }

产生相当明确的轮廓,但如果 和 曲线在任何地方,则不会检测到该边缘。即,如果我将手横向握住,我会得到上指和下指的边缘,但仅此而已。

我可以做些什么来纠正这个问题并获得真正的优势?

I have a black and white image like this (color overlays are mine, and can be removed):
enter image description here
I need to figure out the edge of the hand shown, how can I do that?

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;
                }
            }
        }

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

時窥 2024-10-22 19:22:37

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!

梦忆晨望 2024-10-22 19:22:37

C++ 上有一个解决方案 http://outliner.codeplex.com/
但将其转换为C#并不是一件容易的事,算法相当复杂。

There is a solution on C++ http://outliner.codeplex.com/
But it will not be an easy task to convert it to C#, the algorithm is quite complex.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文