CoroNet uses Tesseract OCR as a fallback mechanism when the primary GPT-4o-mini vision model fails to detect a license plate. This ensures maximum reliability in license plate extraction.
Tesseract OCR is invoked automatically when the OpenAI model returns “NO_DETECTADA” (app.py:106-110). This dual-engine approach provides robust license plate detection.
The application implements a two-tier OCR strategy:
Primary: GPT-4o-mini vision model (app.py:44-80)
Fallback: Tesseract OCR (app.py:106-110)
app.py
# Primary OCR with GPT-4o-minimatricula = extract_plate_from_image(path)# Fallback with pytesseractif matricula == "NO_DETECTADA": image = Image.open(path) ocr_text = pytesseract.image_to_string(image, lang="eng") ocr_text = ocr_text.strip().replace(" ", "").replace("\n", "").upper() matricula = "".join([c for c in ocr_text if c.isalnum() or c == "-"])[:10]
# English (usually included by default)sudo apt install tesseract-ocr-eng# Spanish (optional)sudo apt install tesseract-ocr-spa# View all available languagesapt-cache search tesseract-ocr
4
Verify installation
tesseract --versiontesseract --list-langs
Expected output:
tesseract 4.x.x or 5.x.x leptonica-1.x.xList of available languages (2):engosd
1
Install Tesseract
sudo dnf install tesseract# or for older versions:sudo yum install tesseract
The fallback OCR implementation in CoroNet (app.py:106-110):
if matricula == "NO_DETECTADA": image = Image.open(path) ocr_text = pytesseract.image_to_string(image, lang="eng") ocr_text = ocr_text.strip().replace(" ", "").replace("\n", "").upper() matricula = "".join([c for c in ocr_text if c.isalnum() or c == "-"])[:10]
This implementation:
Opens the image using PIL (Pillow)
Runs Tesseract OCR with English language data
Cleans the output (removes spaces, newlines, converts to uppercase)
Test your Tesseract installation with a sample image:
import pytesseractfrom PIL import Imageimport osdef test_tesseract(): # Check if Tesseract is accessible try: version = pytesseract.get_tesseract_version() print(f"✓ Tesseract version: {version}") except Exception as e: print(f"✗ Tesseract not found: {e}") return # List available languages try: langs = pytesseract.get_languages() print(f"✓ Available languages: {', '.join(langs)}") except Exception as e: print(f"✗ Error listing languages: {e}") # Test with a sample image if os.path.exists('uploads/sample.jpg'): image = Image.open('uploads/sample.jpg') text = pytesseract.image_to_string(image, lang='eng') print(f"✓ OCR Result: {text}")if __name__ == "__main__": test_tesseract()
Tesseract OCR is significantly faster than the OpenAI vision model but may have lower accuracy for complex images. The dual-engine approach balances accuracy and speed.