从简单的 2D 图像中提取线段的简单有效的方法是什么?
具体来说,我试图从游戏“小行星”的屏幕截图中提取所有相关的线段。我已经研究了各种边缘检测方法,但似乎没有一种方法适合我的问题,原因有两个:
它们检测平滑的轮廓,而我只需要检测直线段,并且只需要检测在一定范围内的直线段。长度。现在,这些限制应该使我的任务比一般情况容易得多,但我不想只使用完整的边缘检测器,然后清除曲线的结果,因为这会成本高昂。对于我的目的来说,速度是最重要的。
它们输出一个修改后的图像,其中边缘突出显示,而我想要一组像素坐标来描述检测到的线段的端点。或者,每个线段中包含的所有像素的列表也可以。
我有一种可能的解决方案涉及 hough 变换 ,但我不知道如何使用它来获取线段的实际位置(即像素空间中的端点)。尽管即使我这样做了,我也不知道这是否是最简单或最有效的做事方式,因此问题标题的一般措辞也是如此。
最后,这是一个示例图像:
请注意,所有主要线条的长度和密度都相似,并且整体图像对比度非常高。我希望我的问题的解决方案能够利用这些功能,因为效率再次至关重要。
需要注意的是:虽然此上下文中的大多数线段都是多边形的一部分,但我不想要依赖于这一事实的解决方案。
Specifically, I'm trying to extract all of the relevant line segments from screenshots of the game 'asteroids'. I've looked through the various methods for edge detection, but none seem to fit my problem for two reasons:
They detect smooth contours, whereas I just need the detection of straight line segments, and only those within a certain range of length. Now, these constraints should make my task considerably easier than the general case, but I don't want to just use a full blown edge detector and then clear the result of curved lines, as that would be prohibitively costly. Speed is of the utmost importance for my purposes.
They output a modified image where the edges are highlights, whereas I want a set of pixel coordinates depicting the endpoints of the detected line segments. Alternatively, a list of all of the pixels included in each segment would work as well.
I have an inkling that one possible solution would involve a hough transform, but I don't know how to use this to get the actual locations of the line segments (i.e. endpoints in pixel space). Though even if I did, I have no idea if that would be the simplest or most efficient way of doing things, hence the general wording of the question title.
Lastly, here's a sample image:
Notice that all of the major lines are similar in length and density, and that the overall image contrast is very high. I'm hoping the solution to my problem will exploit these features, because again, efficiency is paramount.
One caveat: while most of the line segments in this context are part of a polygon, I don't want a solution that relies on this fact.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看线段检测器算法。
他们的做法如下:
您可以找到令人印象深刻的 视频位于页面底部。
有一个开箱即用的 C 实现(与 C++ 编译器一起使用)。只有一两个文件,并且没有其他依赖项
,但是请注意,该算法采用 GNU Allegro GPL 许可证。
Have a look at the Line Segment Detector algorithm.
Here's what they do :
You can find an impressive video at the bottom of the page.
There's a C implementation (that works with C++ compilers) that works out of the box. There are just one or two files, and no additional dependencies
But, be warned, the algorithm is under the GNU Allegro GPL license.
另请查看 EDlines http://ceng.anadolu.edu.tr/cv/EDLines/
非常快并且提供非常有用的输出
Also check out EDlines http://ceng.anadolu.edu.tr/cv/EDLines/
Very fast and provides a very useful output