Skip to main content
FastANPR logo

Build Status Build Status Build Status Build Status Build Status Build Status GitHub release (latest by date) Python Versions License: AGPL-3.0 GitHub stars

Introduction

A fast automatic number-plate recognition (ANPR) library. This package employs YOLOv8, a lightweight model, for detection, and Paddle OCR, a lightweight optical character recognition (OCR) library, for recognizing text in detected number plates. Example outputs

Installation

You can install the package using pip:

pip install fastanpr

Requirements

  • Windows:
    • Python >=3.8, <3.11
  • Ubuntu, macOS, Raspbian:
    • Python >=3.8, <3.12

Usage

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:

uvicorn api:app

Usage

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:

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) to comply with the licensing requirements.

For more details on the YOLOv8 model and its license, please visit the Ultralytics GitHub repository.

Contributing

We warmly welcome contributions from the community! If you're interested in contributing to this project, please start by reading our 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.

Release files for fastanpr 0.1.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastanpr 0.1.13
File Size Uploaded
fastanpr-0.1.13.tar.gz 5.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastanpr 0.1.13
File Interpreter ABI Platform
fastanpr-0.1.13-py3-none-any.whl Python 3 none any Details

Total release size: 11.4 MB

Release files / fastanpr-0.1.13.tar.gz

Download URL fastanpr-0.1.13.tar.gz
Size 5.7 MB
Tags Source
SHA-256 checksum
How to use checksums
81f924b3dfba82b2e5e6ae4a4e1a29ea36250bc89c4d96bb640f568750b42031
BLAKE2b-256 checksum
How to use checksums
ee585f48c8413b12c9323839fcdc72d5d78774d3e7bf93acf2e61bdd61edb814
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / fastanpr-0.1.13-py3-none-any.whl

Download URL fastanpr-0.1.13-py3-none-any.whl
Size 5.7 MB
Tags Python 3
SHA-256 checksum
How to use checksums
e50469264d81e65106a359d84736608dc994dfadd43f3065ac9be03c228c722a
BLAKE2b-256 checksum
How to use checksums
f0f3882a42e21012838a4952a98fb23b5574deedd02973c1b221211252894f1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.1.13 This release

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page