This is an open-source implementation of the Line Segment Detector paper by Grompone von Gioi et al. This is a complete reimplementation from scratch, as the original source code publsihed with the paper is under the Aferro GPL license, which is much too restrictive for common use cases. As a result, this project is published under a much more permissive MIT license.
Pending release on PyPi, the library can be installed directly from GitHub:
pip3 install git+https://github.com/hdkai/Line-Segment-Detector.git
The library exposes a single method:
def line_segment_detector (image: ndarray, scale=0.8, angle_tolerance=22.5):
"""
Compute line segments in an image using a modified implementation of the
Line Segment Detector paper: http://www.ipol.im/pub/art/2012/gjmr-lsd/article.pdf
Parameters:
image (ndarray): Input image, either RGB or greyscale.
scale (float): Downscale factor for processing.
angle_tolerance (float): Angle tolerance in degrees.
Returns:
ndarray: Lines array with shape (N,8), with each row being [ x1, y1, x2, y2, cx, cy, l, w ].
"""
The function accepts a single color or greyscale image, and returns an Nx8
matrix, where each row contains:
- The
x
coordinate of the first point on the line segment. - The
y
coordinate of the first point on the line segment. - The
x
coordinate of the second point on the line segment. - The
y
coordinate of the second point on the line segment. - The
x
coordinate of the center of the line segment. - The
y
coordinate of the center of the line segment. - The length of the line segment
l
. - The width of the line segment
w
. For every detected line,w < l
.
- Python 3.6+
- Cython 0.29.21+.