Metadata-Version: 2.1
Name: houghvg
Version: 0.2.0
Summary: A Hough Transform Toolbox Based on Virtual Grids
Keywords: Hough transform,parallelism,mesh,virtual grid,fingerprint,nanobind,C++,Python,image processing,computer vision,opencv
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Image Processing
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Operating System :: Microsoft :: Windows
Project-URL: Homepage, https://github.com/moise-github/HoughVG_cpp
Project-URL: Repository, https://github.com/moise-github/HoughVG_cpp
Project-URL: Issues, https://github.com/moise-github/HoughVG_cpp/issues
Requires-Python: >=3.9
Requires-Dist: numpy<2.5,>=1.26
Provides-Extra: examples
Requires-Dist: opencv-python>=4.9; extra == "examples"
Requires-Dist: numpy<2.5,>=1.26; extra == "examples"
Description-Content-Type: text/markdown

# HoughVG :  Hough transform on Virtual Grids: Hough transform toolbox for straight-lines detection and fingerprints recognition
HoughVG is a Virtual Grid-Based Hough transform toolbox for straight-lines detection and fingerprints recognition. It brings together several innovative variants of the Virtual Grid-Based Hough transform, including the rectangular, triangular, hexagonal and octagonal Hough transforms for straight-line detection, as well as the generalized Hough transform using virtual rectangular grid, specially adapted for fingerprint recognition.

This version of **HoughVG** is implemented in **C++** and exposed to **Python** using **nanobind**.

At this stage, **fingerprint recognition** and **parallel processing** are not yet available in this release. These features will be added in a future version.



## Installation From PyPI

Install the package with pip:

```powershell
python -m pip install houghvg
```


## Usage 
### Straight-lines detection
```python
import time
import cv2
import houghvg
import numpy as np

PI = np.pi
IMAGE_PATH =  "univ.PNG"
THRESHOLD = 31

def draw_hough_lines(image, lines, color):
    output = image.copy()
    if lines is None:
        return output

    for line in lines:
        rho = float(line[0])
        theta = float(line[1])
        cos_theta = np.cos(theta)
        sin_theta = np.sin(theta)

        pt1 = (
            int(round(rho * cos_theta + 1000 * (-sin_theta))),
            int(round(rho * sin_theta + 1000 * cos_theta)),
        )
        pt2 = (
            int(round(rho * cos_theta - 1000 * (-sin_theta))),
            int(round(rho * sin_theta - 1000 * cos_theta)),
        )
        cv2.line(output, pt1, pt2, color, 2, cv2.LINE_AA)

    return output

def main():
    image = cv2.imread(str(IMAGE_PATH), cv2.IMREAD_COLOR)
    if image is None:
        raise RuntimeError(f"Impossible de charger {IMAGE_PATH}")

    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(gray, 100, 200)

    t0 = time.perf_counter()
    houghvg_lines = houghvg.HoughLines(
        edges,
        grid_type=houghvg.GridType.OCTOGONAL,
        rho=1.0,
        theta=PI / 180.0,
        threshold=THRESHOLD,
        cell_width_base=4.0,
        cell_height=5.0,
        gamma=2.0,
        rate=0.4,
        use_parallel=False,
        return_numpy=True,
    )
    
    img_houghvg_lines = draw_hough_lines(image, houghvg_lines[:, :2], (0, 255, 0))
    
    cv2.imshow("HoughVG : Detected lines", img_houghvg_lines)
    print("Appuie sur une touche dans une fenetre OpenCV pour fermer.")
    cv2.waitKey(0)
    cv2.destroyAllWindows()
```

## Features

- Rectangular, triangular, hexagonal, and octagonal virtual grids.
- Python bindings built with nanobind.
- Optional NumPy return mode: `return_numpy=True` returns an `Nx3` `float32` array containing `[rho, theta, votes]`.
- Example script comparing `houghvg.HoughLines` and `cv2.HoughLines` visually and temporally.

## Requirements

This package contains a native C++ extension. The current Windows build links against OpenCV 4.9
