This project provides a Flask-based API for license plate recognition using computer vision techniques and OCR (Optical Character Recognition).
- License plate detection from images
- Text recognition from detected license plates
- Support for both Tesseract OCR and EasyOCR
- Error handling and logging
- Configurable through environment variables
- Image preprocessing and enhancement
- Supports various image formats
- Saves processed license plate images
- Python 3.8+
- pip
- Tesseract OCR installed on your system
-
Clone the repository:
git clone https://github.com/techbyvj/license-plate-recognition-python.git cd license-plate-recognition-api
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up environment variables: Create a
.env
file in the project root and add the following:PORT=5000
To start the API server, run:
python main.py
The API will be available at http://localhost:5000
(or the port you specified in the .env file).
- License Plate Recognition
- URL:
/process_image
- Method: POST
- Body: Form-data with key 'file' and value as the image file
- Response: JSON object containing the recognized license plate text
- URL:
Example using curl:
curl -X POST -F "file=@path/to/your/image.jpg" http://localhost:5000/process_image
The API uses custom error codes and messages for different scenarios. These are defined in the constants.py
file:
class ErrorCode(Enum):
NO_FILE = 1001
NO_SELECTED_FILE = 1002
NO_PLATE_DETECTED = 1003
PROCESSING_ERROR = 1004
class Constants:
class ErrorMessage:
NO_FILE = "No file part in the request"
NO_SELECTED_FILE = "No selected file"
NO_PLATE_DETECTED = "No license plate detected or text recognized"
PROCESSING_ERROR = "Error processing image"
The image processing pipeline includes the following steps:
- Convert the image to HSV color space
- Create yellow and white masks to isolate potential license plate regions
- Apply morphological operations to reduce noise
- Find and analyze contours to detect the license plate
- Use OCR (Tesseract and EasyOCR) to recognize text on the license plate
For more detailed information about the implementation, usage, and additional features, please visit the project's GitHub repository:
https://github.com/techbyvj/PlateRecognizePy
This repository contains the full source code, documentation, and examples to help you get started with the License Plate Recognition API.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Follow the author on X (Twitter): @saidbyvj