GithubHelp home page GithubHelp logo

arvindrajan92 / fastanpr Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 12.22 MB

A fast automatic number-plate recognition (ANPR) library

Home Page: https://pypi.org/project/fastanpr/

License: GNU Affero General Public License v3.0

Python 96.07% Dockerfile 3.93%
anpr detection fast paddleocr paddlepaddle python recognition yolo licence-plates number-plate-recognition number-plates yolov8 licence-plate-recognition

fastanpr's Introduction

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.

fastanpr's People

Contributors

arvindrajan92 avatar

Stargazers

Sachintha avatar SAMVEDNA avatar

Watchers

 avatar

fastanpr's Issues

Add An API Server Using FastAPI

Is your feature request related to a problem? Please describe.
I cannot host an API service.

Describe the solution you'd like
FastANPR as a service using FastAPI library.

Describe alternatives you've considered
The alternative would be to use Flash or Django framework.

Additional context
None

Getting requirements to build wheel did not run successfully.

on windows, in CMD when trying to install

Collecting lmdb (from paddleocr>=2.7.0.3->fastanpr)
Using cached lmdb-1.4.1.tar.gz (881 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [27 lines of output]
py-lmdb: Using bundled liblmdb with py-lmdb patches; override with LMDB_FORCE_SYSTEM=1 or LMDB_PURE=1.
Traceback (most recent call last):
File "", line 92, in
ModuleNotFoundError: No module named 'patch_ng'

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "C:\Users\rafariva\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
      main()
    File "C:\Users\rafariva\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\rafariva\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
      return hook(config_settings)
             ^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\rafariva\AppData\Local\Temp\pip-build-env-k6yzy5r8\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\rafariva\AppData\Local\Temp\pip-build-env-k6yzy5r8\overlay\Lib\site-packages\setuptools\build_meta.py", line 295, in _get_build_requires
      self.run_setup()
    File "C:\Users\rafariva\AppData\Local\Temp\pip-build-env-k6yzy5r8\overlay\Lib\site-packages\setuptools\build_meta.py", line 487, in run_setup
      super().run_setup(setup_script=setup_script)
    File "C:\Users\rafariva\AppData\Local\Temp\pip-build-env-k6yzy5r8\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup
      exec(code, locals())
    File "<string>", line 94, in <module>
  Exception: Building py-lmdb from source on Windows requires the "patch-ng" python module.
  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.