axis-line-detector
Fast, standalone detector for near-horizontal and near-vertical lines in images. Purpose-built for scanned documents, forms, and tables where lines fall within a few degrees of an axis.
Similar in spirit to OpenCV's FastLineDetector, but restricted to axis-aligned output and much simpler, faster and more robust (more accurate).
Install
pip install axis-line-detector # core detector (NumPy only)
pip install axis-line-detector[overlay] # + Pillow for file bytes and overlay()
Building from source requires a C++17 compiler (GCC 7+, Clang 5+, MSVC 2017+).
Usage
from axis_line_detector import detect, overlay
with open("form.png", "rb") as f:
data = f.read()
# Detect the lines!
# Ignore lines shorter than 50 pixels; we only want longer lines that span form sections/tables.
lines = detect(data, min_length=50)
# Output is a (N, 4) numpy.float32 array with the detected lines: (x1, y1, x2, y2).
for x1, y1, x2, y2 in lines:
print(f"({x1:.1f}, {y1:.1f}) -> ({x2:.1f}, {y2:.1f})")
# Overlay the detections onto the original image for quick visual inspection.
overlay(lines, data, "form_overlay.png")
Accepted inputs
Both detect and overlay accept the same set of image inputs. The Python
wrapper normalizes them before calling the C++ core:
bytes/bytearray/memoryview— raw encoded image file contents (PNG, JPEG, …), decoded with Pillow ([overlay]extra).str/os.PathLike— filesystem path to an image file (Pillow).- 2-D numpy array — grayscale.
- 3-D, 1 or 2 channels — first channel used.
- 3-D, 3 or 4 channels — interpreted as RGB/RGBA and reduced with
ITU-R BT.601 luminance. For BGR sources (OpenCV), reverse first:
image[..., ::-1]. uint16— rescaled from[0, 65535]to[0, 255].float— assumed in[0.0, 1.0], scaled to[0, 255], clipped.bool—False→0,True→255.- Other integer dtypes are clipped to
[0, 255]and cast.
Non-contiguous inputs are copied automatically.
Visual inspection
overlay(lines, image, output_path, *, seed=0) renders each detected line into a PNG, and preserves the source image's
colors. Pass the same image you gave to detect so the overlay lines up with the original pixels.
overlay and the file-bytes/path inputs to detect require Pillow;
install with pip install axis-line-detector[overlay] or separately with pip install Pillow.
Behavior
Fixed characteristics of the detector (see src/axis_line_detector.cpp for
full documentation and rationale):
min_lengthis required and must be a positive integer. Lines shorter than this are ignored = not returned fromdetect().- Only lines within 5 degrees of horizontal or vertical are returned (more "diagonal" lines are ignored because we mostly care about slightly rotated documents and form scans).
- Up to 25,000 fragments per axis are retained (a forced cut-off to avoid wasting too much time on weird / adversarial images).
License
MIT. See LICENSE.
Release files for axis-line-detector 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| axis_line_detector-0.1.2.tar.gz | 20.9 kB | Details |
Release files / axis_line_detector-0.1.2.tar.gz
| Download URL | axis_line_detector-0.1.2.tar.gz |
|---|---|
| Size | 20.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d7e458da958fdd347d666d6198c030cb9e70f1efdba7ff8e590d0d8d69ef8ba
|
|
BLAKE2b-256 checksum How to use checksums |
c169f7af1d886f3db42e08c3ba9544d463f3fe528a9321f1b461a3c597bbffa8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|