EasyOCR
EasyOCR is an end-to-end multi-lingual optical character recognition (OCR) solution designed for ease of use. It supports over 80 languages and provides pre-trained models for common use cases. The current version is 1.7.2, with minor releases focusing on compatibility and bug fixes, and major updates introducing new features like detector networks or Apple Silicon support.
Warnings
- gotcha EasyOCR runs on PyTorch. For GPU acceleration, you MUST install a CUDA-enabled version of PyTorch separately. `pip install easyocr` will only install a CPU-compatible PyTorch if it's not already present.
- gotcha The first initialization of `easyocr.Reader` for a new language will download large model files (several hundreds of MBs). This requires an internet connection and can cause a delay.
- gotcha Not all languages are supported by pre-trained models. Specifying an unsupported language or a non-existent model name will lead to an error or unexpected behavior.
- gotcha The `detect_network` argument was introduced in v1.6.0 to allow specifying alternative text detectors (e.g., 'dbnet18'). Prior to this, only the CRAFT detector was available. If you upgrade from an older version or need to ensure a specific detector, you might need to explicitly set this argument.
- gotcha EasyOCR can be memory-intensive, especially when processing high-resolution images or multiple languages simultaneously, consuming significant RAM or VRAM.
Install
-
pip install easyocr -
pip install easyocr opencv-python-headless -
pip install easyocr torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
Imports
- Reader
import easyocr reader = easyocr.Reader(['en'])
Quickstart
import easyocr
import os
from PIL import Image, ImageDraw
# Create a dummy image for demonstration purposes
dummy_image_path = 'easyocr_demo_image.png'
img = Image.new('RGB', (400, 100), color = (255, 255, 255))
d = ImageDraw.Draw(img)
d.text((10, 10), "Hello EasyOCR!\nThis is a test.", fill=(0,0,0))
img.save(dummy_image_path)
# Initialize Reader with desired languages.
# Models are downloaded on first run for each language.
# Set gpu=True if you have CUDA-enabled PyTorch installed, otherwise leave as False.
reader = easyocr.Reader(['en', 'fr'], gpu=False)
# Perform OCR on the image file
# result will be a list of tuples: (bounding_box, text, confidence)
result = reader.readtext(dummy_image_path)
print(f"OCR Results for '{dummy_image_path}':")
for (bbox, text, conf) in result:
print(f" Text: '{text}', Confidence: {conf:.2f}")
# Clean up the dummy image
os.remove(dummy_image_path)