Tools,

YOLO OCR, tested on 20 real scans

48.4% to 94.1%

RapidOCR on two columns, before and after YOLO

Get the free Python script

YOLO draws boxes. OCR reads them.

YOLO is an object detector: it finds where text is, not what it says.

So a YOLO OCR pipeline has three steps:

  1. A YOLO model boxes each text block. Here: DocLayout-YOLO, with its DocStructBench weights.
  2. An OCR reader, Tesseract or RapidOCR, reads each box alone.
  3. The texts are joined in reading order.

I ran that against the same readers on the whole page: 10 one-column book pages and 10 two-column encyclopedia pages.

Two columns: RapidOCR gains, Tesseract does not

True words found in order
Way Book, of 1,955 Two columns, of 11,347
Tesseract, whole page 1,878 10,858
YOLO + Tesseract 1,883 10,855
RapidOCR, whole page 1,895 5,491
YOLO + RapidOCR 1,901 10,681

On a whole two-column page, RapidOCR reads its lines top to bottom across both columns, so the columns take turns. On 2 scans it joined two lines into one:

ical composition and other characters led Isaac Comnenus to _the imperial dignity

The left column ends at "led". RapidOCR found 10,549 true words in some order, so the words were there, just mixed.

Tesseract (psm 3) finds the columns itself. On the one-column book, YOLO blocks changed almost nothing.

YOLO's box order is not reading order

A two-column encyclopedia page shown twice, with 11 text blocks boxed and numbered. Left, in the order YOLO returns them: 1 and 2 sit in the right column and 3 at the bottom left, so the numbers jump between columns. Right, in column order: 1 to 6 run down the left column, 7 to 11 down the right. A dashed red line marks the page middle, and the right column starts just left of it.
One scan, 11 text blocks. Dashed red: the page middle.
YOLO + Tesseract, true words found in order
Order Book Two columns
As YOLO returns them 1,442 5,708
Top to bottom 1,883 6,719
Left edge before the middle 1,883 9,141
The script's column order 1,883 10,857

Nested boxes print the same text twice

YOLO sometimes boxes the same block twice (6 of the 8 drops here), or a paragraph and a part of it. Both get read, so the text repeats.

Words printed for the book
Way Words printed
Tesseract, whole page 2,041
YOLO + Tesseract, every box 2,456
YOLO + Tesseract, drop_inside 2,001

drop_inside drops a box that lies more than half inside a box YOLO scored higher. It dropped 8 boxes on the 20 pages.

It cost no words in order on the book. On the columns it cost 2 with Tesseract and 4 with RapidOCR.

YOLO was slower in all 4 runs

Seconds for 10 pages, CPU, 2 threads
Way Book Two columns
Tesseract, whole page 28 84
YOLO + Tesseract 57 119
RapidOCR, whole page 39 188
YOLO + RapidOCR 87 245

YOLO alone, in its own run: the first start, with the 40 MB model download, took 6.3 s. Then it took a median 2.8 s a page.

The free script: yolo_ocr.py

It runs DocLayout-YOLO on the CPU, drops nested boxes, sorts the blocks in column order, and reads each one with Tesseract.

pip install doclayout-yolo huggingface_hub pillow
brew install tesseract
python yolo_ocr.py page.jpg > text.txt

The model file, 40 MB, comes from Hugging Face on the first run. doclayout-yolo's code is AGPL-3.0, and the weights are Apache-2.0.

Run as a reader would, on 2 pages, it printed the same text as the bench.

Show the code (71 lines)
"""YOLO OCR: DocLayout-YOLO finds the text blocks on a page image, Tesseract reads each block, in column order.

Setup:  pip install doclayout-yolo huggingface_hub pillow   (and Tesseract: brew install tesseract)
Run:    python yolo_ocr.py page.jpg [page2.jpg ...] > text.txt
The model file (40 MB) comes from Hugging Face on the first run. doclayout-yolo is AGPL-3.0; the weights are Apache-2.0.
"""

import subprocess
import sys
from io import BytesIO

from doclayout_yolo import YOLOv10
from huggingface_hub import hf_hub_download
from PIL import Image

REPO = "juliozhao/DocLayout-YOLO-DocStructBench"
REV = "8c3299a30b8ff29a1503c4431b035b93220f7b11"
TEXT = {"title", "plain text", "figure_caption", "table_caption", "table_footnote", "formula_caption"}
PAD = 8  # pixels around each block, so a tight box does not cut letters

model = YOLOv10(hf_hub_download(REPO, "doclayout_yolo_docstructbench_imgsz1024.pt", revision=REV))


def blocks(path, conf=0.2):
    """Text blocks as (x0, y0, x1, y1, label), in the order YOLO returns them (best score first)."""
    r = model.predict(path, imgsz=1024, conf=conf, device="cpu", verbose=False)[0]
    boxes = [(*b, r.names[int(c)]) for b, c in zip(r.boxes.xyxy.tolist(), r.boxes.cls.tolist())]
    return [b for b in boxes if b[4] in TEXT]


def inside(a, b):
    """Share of box a's area that lies inside box b."""
    w, h = min(a[2], b[2]) - max(a[0], b[0]), min(a[3], b[3]) - max(a[1], b[1])
    return max(0, w) * max(0, h) / ((a[2] - a[0]) * (a[3] - a[1]))


def drop_inside(boxes):
    """Drop a box that lies more than half inside a box YOLO scored higher (YOLO returns the best first)."""
    keep = []
    for b in boxes:
        if all(inside(b, k) <= 0.5 for k in keep):
            keep.append(b)
    return keep


def column_order(boxes, width):
    """Left column top to bottom, then right column. A box is in the right column only if it is narrower than half
    the page and its center is right of the middle, so a one-column page reads top to bottom."""
    # ponytail: 2 columns at most; 3 columns or a full-width block under the columns needs a reading-order model
    return sorted(boxes, key=lambda b: (b[2] - b[0] < width / 2 and (b[0] + b[2]) / 2 >= width / 2, b[1]))


def tesseract(img):
    buf = BytesIO()
    img.save(buf, "PNG")
    p = subprocess.run(["tesseract", "stdin", "stdout", "--psm", "6", "--dpi", "300"], input=buf.getvalue(), capture_output=True, check=True)  # fmt: skip
    return p.stdout.decode().strip()


def crop(img, b):
    return img.crop((max(0, b[0] - PAD), max(0, b[1] - PAD), min(img.width, b[2] + PAD), min(img.height, b[3] + PAD)))


def page_text(path):
    img = Image.open(path).convert("RGB")
    return "\n\n".join(tesseract(crop(img, b)) for b in column_order(drop_inside(blocks(path)), img.width))


if __name__ == "__main__":
    for f in sys.argv[1:]:
        print(page_text(f))

Or skip the detector: our Actor

PDF OCR to Markdown, our Apify Actor, reads the whole page, so you need no detector. Its code at build 0.1.145, run on this Mac:

What I did not test

How I tested it
  • Book: 10 proofread Wikisource book pages, one column, 1920 px JPEGs.
  • Two columns: 10 proofread Wikisource encyclopedia pages of Tesseract two columns, left column first.
  • Their works: Britannica 1911, New International, American Cyclopaedia and Collier's.
  • doclayout-yolo 0.0.4 and the DocStructBench weights at commit 8c3299a3.
  • Image size 1024, confidence 0.2 (its README value), on the CPU with 2 threads.
  • Kept: title, plain text, caption and table footnote blocks. Dropped: "abandon" (running heads, page numbers), figures, tables and formulas.
  • Each block cropped with an 8 px pad and read alone: Tesseract --psm 6, and RapidOCR.
  • Whole page: Tesseract 5.5.4, --psm 3 --dpi 300.
  • RapidOCR 3.10.0 with its default models, both ways.
  • Score: true words found in order, against the proofread text.
  • Speed: each way on the same page, one right after the other, so both saw the same Mac load. The model was loaded first.
  • Total Mac CPU at the start of each set: 336% and 259%.
  • Python 3.12, torch 2.15.0 and onnxruntime 1.32.0.
  • The Actor: its own code, run on this Mac with text output and its defaults. No Apify run.
  • Apple M5 Max, macOS 26.6.
  • Scripts and results stay in our private repo, in research/bench/yolo-ocr-2026-11-26/.
Sources

Questions people ask

Can YOLO do OCR?

Not by itself. YOLO is an object detector: it draws boxes and labels them. To get text, crop each box and read it with an OCR reader, such as Tesseract or RapidOCR.

Does a YOLO model make OCR more accurate?

In our test, it helped where the reader mixed up columns and changed almost nothing elsewhere. On our two-column scans, RapidOCR went from 48.4% to 94.1% of words in order. Tesseract finds columns itself and gained nothing.

Why is my YOLO OCR text out of order?

YOLO returns boxes best score first, not in reading order. Sort them: left column top to bottom, then the right column. column_order in our script does that for 2 columns.

Which YOLO model finds text blocks on a page?

We used DocLayout-YOLO with its DocStructBench weights. It labels titles, plain text, captions, tables, figures and formulas, and calls page clutter such as running heads abandon.