Metadata-Version: 2.4
Name: sinapsis-fast-alpr
Version: 0.1.1
Summary: Fast ALPR license plate recognition
Author-email: SinapsisAI <dev@sinapsis.tech>
Project-URL: Homepage, https://sinapsis.tech
Project-URL: Documentation, https://docs.sinapsis.tech/docs
Project-URL: Tutorials, https://docs.sinapsis.tech/tutorials
Project-URL: Repository, https://github.com/Sinapsis-AI/sinapsis-fastl-alpr.git
Requires-Python: >=3.10.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fast-alpr[onnx-gpu]>=0.4.0
Requires-Dist: onnxruntime==1.23.0
Requires-Dist: onnxruntime-gpu==1.23.0
Requires-Dist: opencv-contrib-python>=4.11.0.86
Requires-Dist: sinapsis>=0.2.27
Requires-Dist: torch==2.8.0
Requires-Dist: transformers<5.0
Provides-Extra: detection
Requires-Dist: sinapsis-rfdetr>=0.1.14; extra == "detection"
Provides-Extra: tracking
Requires-Dist: sinapsis-supervision>=0.1.6; extra == "tracking"
Provides-Extra: all
Requires-Dist: sinapsis-fast-alpr[data-tools,detection,tracking]; extra == "all"
Provides-Extra: data-tools
Requires-Dist: sinapsis-data-readers>=0.1.28; extra == "data-tools"
Requires-Dist: sinapsis-data-visualization>=0.1.13; extra == "data-tools"
Requires-Dist: sinapsis-data-writers>=0.1.16; extra == "data-tools"
Dynamic: license-file

[![sp](https://img.shields.io/badge/lang-sp-red.svg)](https://github.com/Sinapsis-AI/sinapsis-fast-alpr/blob/main/README.es.md)
<h1 align="center">
<br>
<br>
<a href="https://sinapsis.tech/">
  <img
    src="https://github.com/Sinapsis-AI/brand-resources/blob/main/sinapsis_logo/4x/logo.png?raw=true"
    alt="" width="300">
</a>
<br>
Sinapsis Fast ALPR
<br>
</h1>

<h4 align="center">Templates for Automatic License Plate Recognition and speed calculation.</h4>

<p align="center">
<a href="#installation">🐍 Installation</a> •
<a href="#features">🚀 Features</a> •
<a href="#usage-example">📚 Example usage</a> •
<a href="#documentation">📙 Documentation</a> •
<a href="#license">🔍 License</a>
</p>

The `sinapsis-fast-alpr` module provides templates for calculation of vehicle speed and license plate recognition in videos, through Fast ALPR and RFDETR.


<h2 id="installation">🐍 Installation</h2>

Install using your package manager of choice. We encourage the use of `uv`

```bash
uv pip install sinapsis-fast-alpr
```
or wiht raw pip
```bash
pip install sinapsis-fast-alpr
```

> [!IMPORTANT]
> Templates in sinapsis-fast-alpr package may require extra dependencies. For development, we recommend installing the package with all the optional dependencies:

```bash
uv pip install sinapsis-fast-alpr[all] --extra-index-url https://pypi.sinapsis.tech
```
or
```bash
pip install sinapsis-fast-alpr[all] --extra-index-url https://pypi.sinapsis.tech
```


<h2 id="features">🚀 Features</h2>

<h3> Templates Supported</h3>

The **Sinapsis Fast ALPR** module provides the following templates for Speed Calculation and License Plate Recognition.

- **ClassFilter**: Limits object detections to certain given classes.
- **FastALPR**: Runs fast-alpr pipeline to detect and recognize liense plates.
- **PerspectiveTransform**: Transforms the perspective of a camera into a rectangle to compensate for the view and works along with ObjectSpeedCalculation template.
- **ObjectSpeedCalculation**: Approximates the speed of objects detected in video.


<h2 id="usage-example">📚 Example usage</h2>

The example available in <code>sinapsis-fast-alpr/src/sinapsis_fast_alpr/configs/speed_calculation.yaml</code> demonstrates how to use the sinapsis-fast-alpr templates. This configuration defines an **agent** and a sequence of **templates** to run fast-alpr and speed calculation.

To adjust the configuration details for your own video, you can use the pick-coordinates and meters-per-pixel commands to obtain the values to add in the PerspectiveTransform and ObjectSpeedCalculation templates.

- Use <code>uv run pick-coordinates [path to your video]</code> and pick four points of the road to compensate the perspective. The script will give the values for source_points that can be added to **PerspectiveTransform**

- Use <code>uv run meters-per-pixel [path to your video]</code> and pick two points on the road which represent a meter in real-life distance. The script will give a meters_per_pixel value that can be added to **ObjectSpeedCalculation**

- You can substitute the values for frames per second, thresholds, detector models according to your provided video and requirements.

<details>
  <summary id="config"><strong><span style="font-size: 1.2em;">Config file</span></strong></summary>

```yaml
agent:
  name: speed_calculation
  attributes:
    agent_mode: generator

templates:
- template_name: InputTemplate
  class_name: InputTemplate
  attributes: {}

- template_name: Video
  class_name: VideoReaderCV2
  template_input: InputTemplate
  attributes:
    root_dir: path to root dir
    video_file_path: path to video
    batch_size: 1
    device: cpu
    loop_forever: true


- template_name: Inference
  class_name: RFDETRInference
  template_input: Video
  attributes:
    model_params:
      encoder: dinov2_windowed_small
      num_classes: 90
      pretrain_weights: rf-detr-base.pth
      device: cuda
      resolution: 560
    threshold: 0.6

- template_name: Filter
  class_name: ClassFilter
  template_input: Inference
  attributes: {}


- template_name: Track
  class_name: ByteTrack
  template_input: Filter
  attributes:
    track_activation_threshold: 0.2
    minimum_matching_threshold: 0.5
    minimum_consecutive_frames: 1
    frame_rate: 25

- template_name: Transform
  class_name: DetectionPerspectiveTransform
  template_input: Track
  attributes:
    source_points: [[806, 291], [1237, 291], [1562, 931], [325, 920]]

- template_name: Speed
  class_name: ObjectSpeedCalculation
  template_input: Transform
  attributes:
    fps: 25
    meters_per_pixel: 0.06
    speed_limit: 20

- template_name: License
  class_name: FastALPR
  template_input: Speed
  attributes:
    detector_model: yolo-v9-s-608-license-plate-end2end
    ocr_model: cct-xs-v1-global-model
    detection_treshold: 0.6
    ocr_threshold: 0.6

- template_name: Drawer
  class_name: BBoxDrawer
  template_input: License
  attributes:
    overwrite: true
    randomized_color: false
    draw_confidence: true
    draw_extra_labels: true
    text_style:
      font: 0
      font_scale: 0.5
      thickness: 2
    draw_classification_label: true
    classification_label_position: top_right
    text_box_to_border_offset: 0.01

- template_name: VideoWriterCV2
  class_name: VideoWriterCV2
  template_input: Drawer
  attributes:
    root_dir: .
    destination_path: results/video.mp4
    height: -1
    width: -1
    fps: 25
    codec: mp4v
    save_image_batch: false

```
</details>

To run the agent, use:

```bash
uv run sinapsis run sinapsis-fast-alpr/src/sinapsis_fast_alpr/configs/speed_calculation.yaml
```

<h2 id="documentation">📙 Documentation</h2>

Documentation is available on the [sinapsis website](https://docs.sinapsis.tech/docs)

Tutorials for different projects within sinapsis are available at [sinapsis tutorials page](https://docs.sinapsis.tech/tutorials)

<h2 id="license">🔍 License</h2>

The templates in this project are licensed under the AGPLv3 license, which encourages open collaboration and sharing. For more details, please refer to the [LICENSE](LICENSE) file.

The command line interface and pipelines in this project are licensed under the MIT license, which allows for unrestricted use of the software and encourages open collaboration. For more details please refer to the [LICENSE](src/sinapsis_fast-alpr/pipelines/LICENSE) file

For commercial use, please refer to our [official Sinapsis website](https://sinapsis.tech) for information on obtaining a commercial license.
