Metadata-Version: 2.4
Name: axis-line-detector
Version: 0.1.0
Summary: Fast near-horizontal / near-vertical line detector for 8-bit grayscale images.
Author-email: Radim Řehůřek <me@radimrehurek.com>
License: MIT License
        
        Copyright (c) 2026 Radim Řehůřek
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/piskvorky/axis-line-detector
Project-URL: Repository, https://github.com/piskvorky/axis-line-detector
Project-URL: Issues, https://github.com/piskvorky/axis-line-detector/issues
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Image Recognition
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.20
Provides-Extra: overlay
Requires-Dist: Pillow>=9.0; extra == "overlay"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: Pillow>=9.0; extra == "test"
Dynamic: license-file

# 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.

## 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

```python
from axis_line_detector import detect, overlay

with open("form.png", "rb") as f:
    data = f.read()

lines = detect(data, min_length=50)  # numpy.ndarray, shape (N, 4), float32
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):

- Only lines within **5 degrees** of horizontal or vertical are returned.
- Up to 25,000 fragments per axis are retained (a forced cut-off to avoid spending too much time on weird images).
- `min_length` is required and must be a positive integer.

## License

MIT. See [LICENSE](LICENSE).
