EasyOCR

1.7.2 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart code creates a simple dummy image with text, then initializes an EasyOCR Reader for English and French. The first time you run this for a new language, it will download the necessary language models. It then performs OCR on the image and prints the detected text along with its confidence score. For GPU acceleration, ensure you have correctly installed PyTorch with CUDA support and set `gpu=True`.

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)

view raw JSON →