This Python project uses OpenCV and Tesseract OCR to detect and extract license plate text from car images β optimized for French license plates.
You place images of vehicles inside a cars/ folder, and the script will process each image to locate the license plate and extract its text.
- Automatic detection of license plates using image processing
- Optical Character Recognition (OCR) with
pytesseract - Optimized for French plate formats (e.g.
AB-123-CD) - Preprocessing pipeline for better OCR accuracy
- CLI output of image paths and detected plate text
- Python 3.6+
- OpenCV
- pytesseract
- Tesseract OCR engine installed on your system
pip install opencv-python pytesseract numpysudo apt update
sudo apt install tesseract-ocrbrew install tesseract- Download the installer from: https://github.com/tesseract-ocr/tesseract
- Make sure to add the Tesseract installation path to your systemβs PATH.
- Example:
C:\Program Files\Tesseract-OCR\tesseract.exe
If needed, you can specify the Tesseract executable path in the script:
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'project/
β
βββ cars/ # Input images of vehicles
βββ main.py # Main script for processing
βββ README.md # This file
python main.pyThe script will print the detected license plate text for each image in the cars/ directory.
- Converts the image to grayscale and enhances contrast.
- Uses edge detection and contour finding to locate license plate candidates.
- Filters candidates based on aspect ratio (French plates ~4:1).
- Extracts the plate region and applies thresholding.
- Uses
pytesseractto perform OCR on the region. - Prints the extracted text if it resembles a valid French plate.
π Reading French car plates from images in 'cars/' folder...
π· cars/car1.jpg β€ π·οΈ Plate: AB-123-CD
π· cars/car2.jpg β€ π·οΈ Plate: ZY-987-WX
This script is optimized for French license plates, typically formatted like:
AB-123-CD1234 AB 75
For other country formats, some logic may need to be adjusted.
- Support for other countries (e.g. Iran, Germany)
- GUI for drag-and-drop detection
- Model-based plate detection with YOLO or other deep learning methods
- Integration with Flask for web interface
This project is open-source and free to use under the MIT License.
Feel free to fork, improve, or submit a pull request! π