What is a simple and efficient method for extracting line segments from a simple 2D image?

In particular, I am trying to extract all the relevant line segments from screenshots of the asteroids game. I looked at various edge detection methods, but none of them are suitable for my problem for two reasons:

  • They detect smooth contours, while I just need to identify segments of a straight line and only those that are in a certain range of length. Now these restrictions should make my task much easier than in the general case, but I don’t want to just use a detector with a full-sized front, and then clear the result of the curved lines, as that would be overly expensive. Speed ​​is paramount to my goals.

  • They display a modified image where the edges are glare, while I want a set of pixel coordinates representing the endpoints of the detected line segments. Alternatively, a list of all the pixels included in each segment will also work.

I have a suspicion that one of the possible solutions would include hough transform , but I don’t know how to use this to get the actual locations of the line segments (i.e. end points in the pixel space). Although, even if I did, I have no idea if this was the easiest or most effective way to do things, therefore, the general wording of the title of the question.

Finally, here is a sample image:

enter image description here

Please note that all major lines are similar in length and density and that the overall image contrast is very high. I hope that the solution to my problem will use these features, because again, efficiency is of utmost importance.

One warning: while most line segments in this context are part of a polygon, I don’t want a solution based on this fact.

+4
source share
2 answers

See the line segment detector algorithm .

Here is what they do:

enter image description hereenter image description here

At the bottom of the page you can find an impressive video .

It implements a C implementation (which works with C ++ compilers) that works out of the box. There are only one or two files, and no additional dependencies

But, be careful, the algorithm is licensed under the GNU Allegro GPL.

+4
source

Also check out the EDlines http://ceng.anadolu.edu.tr/cv/EDLines/

Very fast and provides a very useful exit

+1
source

All Articles