<img src="misc/logo.jpg" alt="FastANPR logo" style="width:100%;">
[![Build Status](https://github.com/arvindrajan92/fastanpr/actions/workflows/merge.yaml/badge.svg)](https://github.com/arvindrajan92/fastanpr/actions)
[![Build Status](https://github.com/arvindrajan92/fastanpr/actions/workflows/merge_macos.yaml/badge.svg)](https://github.com/arvindrajan92/fastanpr/actions)
[![Build Status](https://github.com/arvindrajan92/fastanpr/actions/workflows/merge_raspbian.yaml/badge.svg)](https://github.com/arvindrajan92/fastanpr/actions)
[![Build Status](https://github.com/arvindrajan92/fastanpr/actions/workflows/merge_windows.yaml/badge.svg)](https://github.com/arvindrajan92/fastanpr/actions)
[![Build Status](https://github.com/arvindrajan92/fastanpr/actions/workflows/push.yaml/badge.svg)](https://github.com/arvindrajan92/fastanpr/actions)
[![Build Status](https://github.com/arvindrajan92/fastanpr/actions/workflows/publish.yaml/badge.svg)](https://github.com/arvindrajan92/fastanpr/actions)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/arvindrajan92/fastanpr)](https://github.com/arvindrajan92/fastanpr/releases)
[![Python Versions](https://img.shields.io/badge/python-3.8%20to%203.11-blue)](https://www.python.org/downloads/)
[![License: AGPL-3.0](https://img.shields.io/badge/License-AGPL--3.0-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
[![GitHub stars](https://img.shields.io/github/stars/arvindrajan92/fastanpr?style=social)](https://github.com/arvindrajan92/fastanpr)
## Introduction
A fast *automatic number-plate recognition* (ANPR) library. This package employs [YOLOv8](https://github.com/ultralytics/ultralytics), a lightweight model, for detection, and [Paddle OCR](https://github.com/PaddlePaddle/PaddleOCR), a lightweight *optical character recognition* (OCR) library, for recognizing text in detected number plates.
![Example outputs](misc/sample.png)
## Installation
You can install the package using pip:
```bash
pip install fastanpr
```
### Requirements
- Windows:
- Python >=3.8, <3.11
- Ubuntu, macOS, Raspbian:
- Python >=3.8, <3.12
## Usage
```python
import cv2
from fastanpr import FastANPR
# Create an instance of FastANPR
fast_anpr = FastANPR()
# Load images (images should be of type numpy ndarray)
files = [...]
images = [cv2.cvtColor(cv2.imread(file), cv2.COLOR_BGR2RGB) for file in files]
# Run ANPR on the images
number_plates = await fast_anpr.run(images)
# Print out results
for file, plates in zip(files, number_plates):
print(file)
for plate in plates:
print("Plate Attributes:")
print("Detection bounding box:", plate.det_box)
print("Detection confidence:", plate.det_conf)
print("Recognition text:", plate.rec_text)
print("Recognition polygon:", plate.rec_poly)
print("Recognition confidence:", plate.rec_conf)
print()
print()
```
### Class: FastANPR
#### Methods
##### run(images: List[np.ndarray] -> List[List[NumberPlate]]
Runs ANPR on a list of images and return a list of detected number plates.
- **Parameters:**
- `images` (List[np.ndarray]): A list of images represented as numpy ndarray.
- **Returns:**
- `List[List[NumberPlate]]`: A list of detected number plates for every image.
### Class: NumberPlate
#### Attributes
- `det_box` (List[int]): Bounding box coordinates of detected number plate.
- `det_conf` (float): Confidence score of number plate detection.
- `rec_text` (str): Recognized plate number.
- `rec_poly` (List[List[int]]): Polygon coordinates of detected texts.
- `rec_conf` (float): Confidence score of recognition.
## FastAPI
To start a FastAPI server locally from your console:
```bash
uvicorn api:app
```
### Usage
```python
import base64
import requests
# Step 1: Read the image file
image_path = 'tests/images/image001.jpg'
with open(image_path, 'rb') as image_file:
image_data = image_file.read()
# Step 2: Convert the image to a base64 encoded string
base64_image_str = base64.b64encode(image_data).decode('utf-8')
# Prepare the data for the POST request (assuming the API expects JSON)
data = {'image': base64_image_str}
# Step 3: Send a POST request
response = requests.post(url='http://127.0.0.1:8000/recognise', json=data)
# Check the response
if response.status_code == 200:
# 'number_plates': [
# {
# 'det_box': [682, 414, 779, 455],
# 'det_conf': 0.29964497685432434,
# 'rec_poly': [[688, 420], [775, 420], [775, 451], [688, 451]],
# 'rec_text': 'BVH826',
# 'rec_conf': 0.940690815448761
# }
# ]
print(response.json())
else:
print(f"Request failed with status code {response.status_code}.")
```
## Docker
Hosting a FastAPI server can also be done by building a docker file as from console:
```bash
docker build -t fastanpr-app .
docker run -p 8000:8000 fastanpr-app
```
## Licence
This project incorporates the YOLOv8 model from Ultralytics, which is licensed under the AGPL-3.0 license. As such, this project is also distributed under the [GNU Affero General Public License v3.0 (AGPL-3.0)](LICENSE) to comply with the licensing requirements.
For more details on the YOLOv8 model and its license, please visit the [Ultralytics GitHub repository](https://github.com/ultralytics/ultralytics).
## Contributing
We warmly welcome contributions from the community! If you're interested in contributing to this project, please start by reading our [CONTRIBUTING.md](CONTRIBUTING.md) guide.
Whether you're looking to submit a bug report, propose a new feature, or contribute code, we're excited to see what you have to offer. Please don't hesitate to reach out by opening an issue or submitting a pull request.
Thank you for considering contributing to our project. Your support helps us make the software better for everyone.
Raw data
{
"_id": null,
"home_page": "https://github.com/arvindrajan92/fastanpr",
"name": "fastanpr",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "python, anpr, fast, licence plate, number plate, detection, recognition, YOLOv8, paddleocr, paddlepaddle",
"author": "arvindrajan92 (Arvind Rajan)",
"author_email": "<arvindrajan92@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/ee/58/5f48c8413b12c9323839fcdc72d5d78774d3e7bf93acf2e61bdd61edb814/fastanpr-0.1.13.tar.gz",
"platform": null,
"description": "<img src=\"misc/logo.jpg\" alt=\"FastANPR logo\" style=\"width:100%;\">\n\n[![Build Status](https://github.com/arvindrajan92/fastanpr/actions/workflows/merge.yaml/badge.svg)](https://github.com/arvindrajan92/fastanpr/actions)\n[![Build Status](https://github.com/arvindrajan92/fastanpr/actions/workflows/merge_macos.yaml/badge.svg)](https://github.com/arvindrajan92/fastanpr/actions)\n[![Build Status](https://github.com/arvindrajan92/fastanpr/actions/workflows/merge_raspbian.yaml/badge.svg)](https://github.com/arvindrajan92/fastanpr/actions)\n[![Build Status](https://github.com/arvindrajan92/fastanpr/actions/workflows/merge_windows.yaml/badge.svg)](https://github.com/arvindrajan92/fastanpr/actions)\n[![Build Status](https://github.com/arvindrajan92/fastanpr/actions/workflows/push.yaml/badge.svg)](https://github.com/arvindrajan92/fastanpr/actions)\n[![Build Status](https://github.com/arvindrajan92/fastanpr/actions/workflows/publish.yaml/badge.svg)](https://github.com/arvindrajan92/fastanpr/actions)\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/arvindrajan92/fastanpr)](https://github.com/arvindrajan92/fastanpr/releases)\n[![Python Versions](https://img.shields.io/badge/python-3.8%20to%203.11-blue)](https://www.python.org/downloads/)\n[![License: AGPL-3.0](https://img.shields.io/badge/License-AGPL--3.0-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)\n[![GitHub stars](https://img.shields.io/github/stars/arvindrajan92/fastanpr?style=social)](https://github.com/arvindrajan92/fastanpr)\n\n## Introduction\nA fast *automatic number-plate recognition* (ANPR) library. This package employs [YOLOv8](https://github.com/ultralytics/ultralytics), a lightweight model, for detection, and [Paddle OCR](https://github.com/PaddlePaddle/PaddleOCR), a lightweight *optical character recognition* (OCR) library, for recognizing text in detected number plates.\n![Example outputs](misc/sample.png)\n\n## Installation\nYou can install the package using pip:\n```bash\npip install fastanpr\n```\n### Requirements\n- Windows:\n - Python >=3.8, <3.11\n- Ubuntu, macOS, Raspbian:\n - Python >=3.8, <3.12\n\n## Usage\n```python\nimport cv2\nfrom fastanpr import FastANPR\n\n# Create an instance of FastANPR\nfast_anpr = FastANPR()\n\n# Load images (images should be of type numpy ndarray)\nfiles = [...]\nimages = [cv2.cvtColor(cv2.imread(file), cv2.COLOR_BGR2RGB) for file in files]\n\n# Run ANPR on the images\nnumber_plates = await fast_anpr.run(images)\n\n# Print out results\nfor file, plates in zip(files, number_plates):\n print(file)\n for plate in plates:\n print(\"Plate Attributes:\")\n print(\"Detection bounding box:\", plate.det_box)\n print(\"Detection confidence:\", plate.det_conf)\n print(\"Recognition text:\", plate.rec_text)\n print(\"Recognition polygon:\", plate.rec_poly)\n print(\"Recognition confidence:\", plate.rec_conf)\n print()\n print()\n```\n### Class: FastANPR\n\n#### Methods\n\n##### run(images: List[np.ndarray] -> List[List[NumberPlate]]\n\nRuns ANPR on a list of images and return a list of detected number plates.\n\n- **Parameters:**\n - `images` (List[np.ndarray]): A list of images represented as numpy ndarray.\n\n- **Returns:**\n - `List[List[NumberPlate]]`: A list of detected number plates for every image.\n\n### Class: NumberPlate\n\n#### Attributes\n\n- `det_box` (List[int]): Bounding box coordinates of detected number plate.\n- `det_conf` (float): Confidence score of number plate detection.\n- `rec_text` (str): Recognized plate number.\n- `rec_poly` (List[List[int]]): Polygon coordinates of detected texts.\n- `rec_conf` (float): Confidence score of recognition.\n\n## FastAPI\nTo start a FastAPI server locally from your console:\n```bash\nuvicorn api:app\n```\n### Usage\n```python\nimport base64\nimport requests\n\n# Step 1: Read the image file\nimage_path = 'tests/images/image001.jpg'\nwith open(image_path, 'rb') as image_file:\n image_data = image_file.read()\n\n# Step 2: Convert the image to a base64 encoded string\nbase64_image_str = base64.b64encode(image_data).decode('utf-8')\n\n# Prepare the data for the POST request (assuming the API expects JSON)\ndata = {'image': base64_image_str}\n\n# Step 3: Send a POST request\nresponse = requests.post(url='http://127.0.0.1:8000/recognise', json=data)\n\n# Check the response\nif response.status_code == 200:\n # 'number_plates': [\n # {\n # 'det_box': [682, 414, 779, 455], \n # 'det_conf': 0.29964497685432434, \n # 'rec_poly': [[688, 420], [775, 420], [775, 451], [688, 451]], \n # 'rec_text': 'BVH826', \n # 'rec_conf': 0.940690815448761\n # }\n # ]\n print(response.json())\nelse:\n print(f\"Request failed with status code {response.status_code}.\")\n```\n\n## Docker\nHosting a FastAPI server can also be done by building a docker file as from console:\n```bash\ndocker build -t fastanpr-app .\ndocker run -p 8000:8000 fastanpr-app\n```\n\n## Licence\nThis project incorporates the YOLOv8 model from Ultralytics, which is licensed under the AGPL-3.0 license. As such, this project is also distributed under the [GNU Affero General Public License v3.0 (AGPL-3.0)](LICENSE) to comply with the licensing requirements.\n\nFor more details on the YOLOv8 model and its license, please visit the [Ultralytics GitHub repository](https://github.com/ultralytics/ultralytics).\n\n## Contributing\n\nWe warmly welcome contributions from the community! If you're interested in contributing to this project, please start by reading our [CONTRIBUTING.md](CONTRIBUTING.md) guide.\n\nWhether you're looking to submit a bug report, propose a new feature, or contribute code, we're excited to see what you have to offer. Please don't hesitate to reach out by opening an issue or submitting a pull request.\n\nThank you for considering contributing to our project. Your support helps us make the software better for everyone.\n",
"bugtrack_url": null,
"license": null,
"summary": "A fast automatic number-plate recognition (ANPR) library",
"version": "0.1.13",
"project_urls": {
"Homepage": "https://github.com/arvindrajan92/fastanpr"
},
"split_keywords": [
"python",
" anpr",
" fast",
" licence plate",
" number plate",
" detection",
" recognition",
" yolov8",
" paddleocr",
" paddlepaddle"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f0f3882a42e21012838a4952a98fb23b5574deedd02973c1b221211252894f1f",
"md5": "b7a657d1eb4dfe40e1edfaa87d52d48f",
"sha256": "e50469264d81e65106a359d84736608dc994dfadd43f3065ac9be03c228c722a"
},
"downloads": -1,
"filename": "fastanpr-0.1.13-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b7a657d1eb4dfe40e1edfaa87d52d48f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 5682229,
"upload_time": "2024-03-30T13:47:11",
"upload_time_iso_8601": "2024-03-30T13:47:11.861146Z",
"url": "https://files.pythonhosted.org/packages/f0/f3/882a42e21012838a4952a98fb23b5574deedd02973c1b221211252894f1f/fastanpr-0.1.13-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ee585f48c8413b12c9323839fcdc72d5d78774d3e7bf93acf2e61bdd61edb814",
"md5": "515738b90058e8d9f49346e334f271c8",
"sha256": "81f924b3dfba82b2e5e6ae4a4e1a29ea36250bc89c4d96bb640f568750b42031"
},
"downloads": -1,
"filename": "fastanpr-0.1.13.tar.gz",
"has_sig": false,
"md5_digest": "515738b90058e8d9f49346e334f271c8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 5684992,
"upload_time": "2024-03-30T13:47:14",
"upload_time_iso_8601": "2024-03-30T13:47:14.476945Z",
"url": "https://files.pythonhosted.org/packages/ee/58/5f48c8413b12c9323839fcdc72d5d78774d3e7bf93acf2e61bdd61edb814/fastanpr-0.1.13.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-30 13:47:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "arvindrajan92",
"github_project": "fastanpr",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "ultralytics",
"specs": [
[
">=",
"8.1.34"
]
]
},
{
"name": "paddlepaddle",
"specs": [
[
">=",
"2.6.1"
]
]
},
{
"name": "paddleocr",
"specs": [
[
"==",
"2.7.2"
]
]
},
{
"name": "fastapi",
"specs": [
[
">=",
"0.110.0"
]
]
},
{
"name": "pydantic",
"specs": [
[
">=",
"2.6.4"
]
]
},
{
"name": "uvicorn",
"specs": [
[
">=",
"0.29.0"
]
]
}
],
"lcname": "fastanpr"
}