Scanned documents and screenshots can contain text you need to process. You may hesitate to send those images to a cloud OCR API. EasyOCR is a Python library that uses deep-learning-based text detection and recognition models to read text from images. I installed it and tested whether text recognition worked with network access disabled.
EasyOCR combines a model that detects text regions with a model that recognizes the text within those regions, and supports 80 or more languages. The EasyOCR project publishes its source code under the Apache 2.0 License (*1).
1. Install EasyOCR
FROM docker.io/library/python:3.12.13-slim
RUN apt-get update && apt-get install -y --no-install-recommends libgl1 libglib2.0-0 && rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir --quiet 'easyocr==1.7.2'
COPY warmup_model.py /tmp/warmup_model.py
RUN python /tmp/warmup_model.py
RUN apt-get update && apt-get install -y --no-install-recommends fonts-dejavu-core && rm -rf /var/lib/apt/lists/*
WORKDIR /work
# warmup_model.py (fetches the detection and recognition models during the build)
import easyocr
import numpy as np
reader = easyocr.Reader(["en"], gpu=False)
reader.readtext(np.zeros((50, 50, 3), dtype="uint8"))
print("warmup ok")
podman build -t easyocr-sandbox .
OpenCV uses libgl1 and libglib2.0-0 for image processing. These are the minimum shared libraries it needs to run.
2. Generate an image and read its text
I generated an image with text for the test instead of importing one from outside, then passed it to EasyOCR. I ran the test with network access disabled.
import easyocr
from PIL import Image, ImageDraw, ImageFont
img = Image.new("RGB", (800, 100), color="white")
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 32)
draw.text((20, 30), "Rootless containers, no network.", fill="black", font=font)
img.save("/work/sample.png")
reader = easyocr.Reader(["en"], gpu=False)
results = reader.readtext("/work/sample.png")
for bbox, text, confidence in results:
print(f"confidence={confidence:.3f} \"{text}\"")
podman run --rm --network none --memory 2g --cpus 2 --pids-limit 512 \
-v "$(pwd)":/work -w /work easyocr-sandbox \
python ocr_demo.py
-v lets the container read from and write to the specified directory. Run the command in an empty directory reserved for the experiment.
The command produced this output:
DETECTED TEXT:
confidence=0.942 "Rootless containers, no network:"
The source image contained “Rootless containers, no network.” (with a period at the end). EasyOCR returned “no network:” (with a colon). EasyOCR got most of the sentence right and made one error: it misread the final punctuation mark. The confidence score was high at 0.942, so an automated process that accepts the result based on this number alone can miss this kind of small error. If you pass OCR results into downstream processing, add a separate check for details such as punctuation and numbers, even when the confidence score is high.
Read text in images without sending them to an external service
You can turn text from paper documents and screenshots into data without sending the images to an external service. Text detection and recognition worked with the network disconnected in this test. Pair OCR output with its confidence score before using it. This gives you more options for using information hidden in images as business data.
Sources
*1 EasyOCR (GitHub), https://github.com/JaidedAI/EasyOCR, Apache 2.0 License