Get Started

Scene Text OCR using Ultralytics YOLO26

What is Scene Text OCR?#

Optical character recognition (OCR) detects and reads text in images. The OCR solution combines an Ultralytics YOLO26-Text detector with PaddleOCR's PP-OCRv6 recognizer, run on ONNX Runtime. It reads photos, documents, and screenshots at any rotation and returns every word with its line in reading order. See Supported Languages for the scripts PP-OCRv6 can read, and the PaddleOCR language models for Korean, Cyrillic, Arabic, Devanagari, Thai, and other scripts.

InputOCR result: 113 words in 23 lines
Part of a blank IRS Form 8802 with printed field labelsThe same form with a box and the recognized text drawn over each of the 113 words read by Ultralytics YOLO26 OCR

solutions.OCR() with the default YOLO26x-Text detector and PP-OCRv6 recognizer on part of a blank IRS Form 8802. The boxes and labels are drawn from result.texts.

Detection and recognition remain separate components, so you can pair any text detector with PP-OCRv6 or your own recognition model.

Why Use Scene Text OCR?#

  • Any rotation: Pages turned 90° or upside down read in the right order without preprocessing.
  • Flexible text geometry: Use detection, OBB, or segmentation models for horizontal, rotated, or irregular text.
  • No extra framework: PP-OCRv6 runs on ONNX Runtime from the Ultralytics assets release, on CPU or CUDA, with no PaddlePaddle install.
  • Structured output: Access recognized text, recognition and detection confidences, source geometry, line numbers, and an annotated image from one results object.

Run Scene Text OCR with YOLO26#

The first run downloads YOLO26x-Text (126 MB) and PP-OCRv6 (77 MB) to the current working directory and installs ONNX Runtime 1.26 or newer (onnxruntime-gpu when CUDA is available). No OCR packages are added to the base Ultralytics dependencies.

Python 3.11 or newer

Recognition on ONNX Runtime, the default, requires Python 3.11 or newer. On Python 3.8 to 3.10, pass a custom recognizer.

Scene Text OCR using Ultralytics YOLO26
yolo solutions ocr source="path/to/video.mp4"
import cv2

from ultralytics import solutions

ocr = solutions.OCR()  # YOLO26x-Text at imgsz=1280 with PP-OCRv6
im0 = cv2.imread("path/to/image.jpg")
assert im0 is not None, "Error reading image file"
result = ocr(im0)
cv2.imwrite("ocr.jpg", result.plot_im)

for text in result.texts:
    print(text["line"], text["text"], text["confidence"])

The CLI saves an annotated ocr.avi under the Ultralytics runs directory and does not print or save the recognized text; use Python to work with the results.

YOLO26-Text Checkpoints and Settings#

The YOLO26-Text family provides n, s, m, l, and x OBB checkpoints, which download automatically, for example solutions.OCR(model="yolo26s-text.pt"). The model and imgsz rows cite the benchmarks below; the recognition-unit and max_det rows come from an earlier test on HierText validation photos, PDF pages scored against their text layers, and screenshots:

SettingDefaultBenchmark result
modelyolo26x-textHighest word F1 of the five checkpoints in the benchmarks: 77.4 at imgsz=1280, with yolo26l-text at 76.6.
imgsz1280With yolo26x-text in the benchmarks, word F1 is 75.1 at 960, 77.4 at 1280, and 78.0 at 1920 on photos of up to 1600 pixels. Smaller images run at their own size, never upscaled.
Recognition unitWordReading words one by one beats reading whole lines by 4 F1 points on photos.
max_det1000A dense document page holds more than the default 300 words.

To train your own OBB text detector, use the Scene Text OBB dataset, which combines COCO-Text and HierText word annotations.

OCR Arguments#

Here's a table with the OCR arguments:

ArgumentTypeDefaultDescription
modelstrNonePath to an Ultralytics YOLO model file.
recognizerstr or Callable'paddleocr'Text-recognition backend: 'paddleocr' (PP-OCRv6 on ONNX Runtime), 'tensorrt' (PP-OCRv6 as an FP16 TensorRT engine on NVIDIA GPUs), a PaddleOCR language model name such as 'korean_PP-OCRv5_mobile_rec', or a callable accepting a BGR crop and returning (text, confidence).
line_widthint2Line thickness for the boxes, keypoints and counts the solution draws.
verboseboolTrueEnables the solution's per-frame log of input shape, class counts and processing speed. The tracking call itself is always silent.

Additionally, the following visualization settings are supported:

ArgumentTypeDefaultDescription
showboolFalseIf True, displays the annotated images or videos in a window. Useful for immediate visual feedback during development or testing.
show_confboolTrueDisplays the confidence score for each detection alongside the label. Gives insight into the model's certainty for each detection.
show_labelsboolTrueDisplays labels for each detection in the visual output. Provides immediate understanding of detected objects.

OCR also passes the inference arguments conf, iou, classes, device, imgsz, max_det, and quantize to the detector; prediction arguments that are not solution arguments, such as agnostic_nms, raise a ValueError. On a CUDA device the built-in recognizers run on the same GPU as the detector; on other devices they run on the CPU.

Choose a Model and Recognizer#

The benchmarks cover photos with about 100 words each on one GPU and on a 50-photo CPU subset, and their best settings are candidates to validate on your own images:

Tested scenarioSettingMeasured
Default settingsDefaults: yolo26x-text.pt and recognizer="paddleocr" at imgsz=128077.4 word F1 in 106.3 ms per image
TensorRT recognizerrecognizer="tensorrt" on an NVIDIA GPU106.3 ms to 57.7 ms per image at the same 77.4 word F1, after a 31-second engine build
Smallest detectormodel="yolo26n-text.pt"Word F1 from 77.4 to 73.6 and latency from 106.3 ms to 93.6 ms, with a checkpoint of 5.7 MB instead of 126 MB
English recognizer on CPUrecognizer="en_PP-OCRv5_mobile_rec"1540 ms to 835 ms per image on CPU with YOLO26x-Text; on the GPU run, word F1 from 77.4 to 73.1
Higher detector resolutionimgsz=1920Word F1 from 77.4 to 78.0 over all 300 photos, 223 of which exceed 1280 pixels

How Scene Text OCR Works#

  1. Detect text: YOLO26 produces axis-aligned boxes, oriented boxes, or segmentation polygons. A mask is read from the minimum-area rectangle around its outline.
  2. Find the page rotation: The text direction is the mean long-side angle of the detected words, weighted by how elongated they are. Words under 2:1, such as single characters, abstain, so a page of only those stays unrotated. On a weak sideways vote, boxes shorter than twice the median short side do not vote, so an isolated upright 1 or I does not turn the page.
  3. Crop words upright: The page is rotated so its text runs left to right, and each word is cropped and rectified there. Words are grouped into lines: same baseline within half the smaller text height, split at gaps wider than 1.5 text heights.
  4. Settle 0° or 180°: A box cannot tell which way its text reads, so OCR reads the 8 widest words of the page both ways and keeps the turn that reads more confidently, since upside-down text reads as low-confidence noise.
  5. Recognize words: PP-OCRv6 reads every word, in width-sorted batches of 8 at 48 px high, padded to at least 320 px as PaddleOCR does. Words that read as nothing are dropped from the results.
  6. Order and render results: Words come back line by line, top to bottom and left to right in the page's own frame. The visualization uses a Unicode font for non-ASCII text such as Chinese.

Coordinates always refer to the original image, not the detector input, rotated page, or recognition crop.

Supported Languages#

PP-OCRv6 can only output characters in its built-in 18,708-character set. The detector finds words in any script, but text in a script outside that set comes back as lookalike characters from the set. For example, Cyrillic ТЕКСТ reads as TEKCT, often with high confidence. Coverage of each language's full alphabet, upper and lower case:

ScriptLanguagesCoverage
Chinese (CJK)Simplified and Traditional Chinese✅ About 15,600 CJK characters
JapaneseJapanese✅ Hiragana, katakana, and kanji
LatinEnglish, French, German, Spanish, Portuguese, Italian, Dutch, Swedish, Finnish, Danish, Norwegian, Polish, Czech, Hungarian, Romanian, Turkish, Croatian, Indonesian, and Malay✅ Every letter and accented letter except German capital ẞ and Spanish ¡
LatinVietnamese⚠️ Partial: most toned vowels, such as ạ, ế, ở, and ữ, are missing
GreekGreek⚠️ Partial: base letters only; accented letters and final ς are missing
CyrillicRussian, Ukrainian, Belarusian, Bulgarian, Serbian, Kazakh, and others❌ Not in PP-OCRv6; use a language model
OtherKorean (Hangul), Arabic, Hebrew, Hindi and other Devanagari, Thai❌ Not in PP-OCRv6; use a language model, except for Hebrew

Digits, ASCII punctuation, and common symbols such as €, £, ¥, and ° are included.

Read Other Scripts#

Pass a PaddleOCR PP-OCRv5 language model name as recognizer to read a script PP-OCRv6 does not cover. Each model runs on ONNX Runtime like PP-OCRv6, downloads from the Ultralytics assets release on first use, and needs no PaddlePaddle install:

ocr = solutions.OCR(recognizer="korean_PP-OCRv5_mobile_rec")
result = ocr(im0)
recognizerScript and example languages
korean_PP-OCRv5_mobile_recKorean (Hangul) and Latin letters
cyrillic_PP-OCRv5_mobile_recCyrillic: Russian, Ukrainian, Bulgarian, Serbian, Kazakh, Mongolian
eslav_PP-OCRv5_mobile_recEast Slavic Cyrillic: Russian, Ukrainian, Belarusian
arabic_PP-OCRv5_mobile_recArabic script: Arabic, Persian, Urdu, Uyghur
devanagari_PP-OCRv5_mobile_recDevanagari: Hindi, Marathi, Nepali
th_PP-OCRv5_mobile_recThai
el_PP-OCRv5_mobile_recGreek, including accented letters and final ς
ta_PP-OCRv5_mobile_recTamil
te_PP-OCRv5_mobile_recTelugu
latin_PP-OCRv5_mobile_recLatin-script languages, in a smaller and faster model than PP-OCRv6
en_PP-OCRv5_mobile_recEnglish, in a smaller and faster model than PP-OCRv6

Pick the model for your text; OCR does not detect the language or switch models. No PP-OCRv5 model reads Hebrew, so pass a custom recognizer for it. See PaddleOCR's text recognition models for each model's accuracy and speed.

Read Text Inside Your Own Detections#

Pass any detection, OBB, or segmentation model as model to read the text inside its boxes, such as license plates or serial numbers. OCR rectifies each detection and reads it as one line of text, so you do not crop anything yourself. Each detection should hold a single line of text that runs along the long side of its box. OCR's imgsz=1280 default applies to your detector too, so pass the size it was trained at:

import cv2

from ultralytics import solutions

ocr = solutions.OCR(model="path/to/license-plate-detector.pt", classes=[0], imgsz=640)  # the detector's training size
im0 = cv2.imread("path/to/image.jpg")
result = ocr(im0)
print([text["text"] for text in result.texts])

The number plate recognition notebook runs this setup on a video.

Read Pre-Cropped Text Lines in Batches#

When another system already crops the text, such as label lines, form fields, or serial numbers, call TextRecognizer to read the crops with PP-OCRv6 and skip detection. It takes a list of BGR numpy.ndarray crops, each holding one line of text, and returns one (text, confidence) tuple per crop, in input order:

import cv2

from ultralytics.solutions.ocr import TextRecognizer

recognize = TextRecognizer()  # PP-OCRv6 on ONNX Runtime, on a CUDA GPU when available, else CPU
crops = [cv2.imread(f) for f in ["path/to/line1.png", "path/to/line2.png", "path/to/line3.png"]]
for text, confidence in recognize(crops, batch=8):
    print(f"{text} ({confidence:.2f})")

The recognizer resizes each crop to 48 pixels high, sorts the crops by width, and reads them batch at a time (8 by default), so crops of similar width share a batch. Pass a model from Read Other Scripts with its .onnx ending, such as TextRecognizer("korean_PP-OCRv5_mobile_rec.onnx"), to read another script. TextRecognizer(device=0, engine=True) reads with the same FP16 TensorRT engine as recognizer="tensorrt", and like OCR it needs Python 3.11 or newer when it reads on ONNX Runtime.

Turn crops upright first

TextRecognizer does not check orientation as OCR does. It reads a crop at least 1.5 times taller than wide turned 90° counterclockwise, which suits text that runs top to bottom, and an upside-down crop returns wrong text.

Use a Custom Recognizer#

Pass a callable to integrate another recognition model without changing the detection, rotation, geometry, or ordering path. The callable runs once for each nonempty BGR numpy.ndarray word crop, including the crops read both ways to settle the page's turn. Return one (text, confidence) tuple per call, not a list of batch results:

Tuple itemAccepted typeDescription
textstrDecoded text for this crop. Return "" when no text is recognized.
confidencefloat, int, or numpy.floatingNumeric recognition confidence, converted to float by the solution.
def recognize(crop):
    # Run your recognition model on the BGR crop and decode its output here.
    return "example", 0.95

ocr = solutions.OCR(model="custom-text.pt", recognizer=recognize)
result = ocr(im0)

The confidence your callable returns decides the 0° or 180° turn, so return the model's score rather than a constant. A recognizer that is neither a name nor a callable raises a TypeError, and an unknown name fails when its .onnx file is not found. When no text is detected, result.texts is empty and the recognizer is not called.

OCR Results#

Each call returns a SolutionResults object. Use result.plot_im for the annotated image and result.texts for records in deterministic reading order:

KeyTypeDescription
textstrRecognized text.
confidencefloatRecognition confidence, kept separate from detection confidence.
detection_confidencefloatYOLO detector confidence.
detection_indexintSource detection index before reading-order sorting.
lineintLine number in reading order; words of one line share it.
polygonlist[list[float]]Original-image polygon: four corners for box and OBB detections, or the mask outline.

result.texts holds one record per word. Group the records by line to get line strings, filter on confidence to drop uncertain reads, and serialize the list directly as JSON:

import json
from itertools import groupby

words = [text for text in result.texts if text["confidence"] >= 0.8]
lines = [" ".join(text["text"] for text in group) for _, group in groupby(words, key=lambda text: text["line"])]
print("\n".join(lines))
print(json.dumps(words))

On the benchmark photos, keeping words with a recognition confidence of at least 0.8 raised word precision from 77.7% to 86.8% and lowered recall from 77.2% to 76.1% with the default settings. Lines are ordered by baseline across the whole page, so a multi-column page is returned row by row rather than column by column.

Benchmarks#

The benchmarks ran Ultralytics 8.4.216 on one NVIDIA RTX PRO 6000 Blackwell Server Edition GPU with ONNX Runtime 1.32 and TensorRT 11.5, on 300 photos sampled evenly from the HierText validation split, whose training split is part of the Scene Text OBB dataset that the YOLO26-Text detectors were trained on. The photos have a long side of 480 to 1600 pixels and return 107 words each on average with the default settings. Accuracy is word F1 in percent against the 29,543 legible ground-truth words: words are lowercased, reduced to letters and digits, kept when at least two characters long, and matched within each image regardless of position. Latency is the mean time in milliseconds of the full ocr(im0) call for one already decoded image, including the annotated image.

Word F1 with recognizer="paddleocr", higher is better. The best value for each model is in bold. Photos smaller than imgsz run at their own size rounded up to a multiple of 32, so imgsz=1920 ran these photos at up to 1600 pixels.

Modelimgsz=640imgsz=960imgsz=1280imgsz=1920
YOLO26n-Text66.571.773.674.2
YOLO26s-Text69.673.375.276.6
YOLO26m-Text71.674.776.577.5
YOLO26l-Text71.974.876.677.6
YOLO26x-Text72.775.177.478.0

Word F1 at imgsz=1280, higher is better. The best value for each model is in bold.

Modelpaddleocrtensorrten_PP-OCRv5_mobile_reclatin_PP-OCRv5_mobile_rec
YOLO26n-Text73.673.669.869.9
YOLO26s-Text75.275.271.571.5
YOLO26m-Text76.576.572.972.4
YOLO26l-Text76.676.672.572.2
YOLO26x-Text77.477.473.173.0

Milliseconds per image at imgsz=1280, lower is better: the median of three passes for each photo, averaged over the 300 photos. The detector column is the YOLO26-Text prediction step alone, with recognizer="paddleocr".

ModelDetector onlypaddleocrtensorrten_PP-OCRv5_mobile_reclatin_PP-OCRv5_mobile_rec
YOLO26n-Text6.993.647.772.173.3
YOLO26s-Text7.195.847.873.474.9
YOLO26m-Text8.895.949.574.376.5
YOLO26l-Text10.699.652.477.679.2
YOLO26x-Text16.4106.357.784.085.3

Milliseconds per image at imgsz=1280 with recognizer="paddleocr", lower is better. Photos are grouped by the number of words YOLO26x-Text returned: 81 photos with 32 words on average, 152 photos with 87, and 67 photos with 242.

Model50 or fewer words51 to 150 wordsmore than 150 words
YOLO26n-Text53.786.3158.4
YOLO26s-Text53.988.6162.6
YOLO26m-Text54.688.7162.2
YOLO26l-Text58.792.5164.9
YOLO26x-Text64.799.7171.6

Milliseconds per image at imgsz=1280, lower is better, on every sixth photo of the benchmark: 50 photos with 104 words on average, one pass each, on an AMD EPYC 9655 host with the default 8 CPU threads. The GPU columns cover the same 50 photos. The English recognizer was measured on CPU for the smallest and the largest model.

ModelCPU, paddleocrCPU, en_PP-OCRv5_mobile_recGPU, paddleocrGPU, tensorrt
YOLO26n-Text104843789.344.9
YOLO26s-Text1092-89.645.2
YOLO26m-Text1244-90.448.2
YOLO26l-Text1302-93.749.9
YOLO26x-Text1540835103.457.2
  • Word count set the latency more than the model did: YOLO26x-Text took 64.7 ms on photos with 50 or fewer words and 171.6 ms on photos with more than 150, while the detector alone took 6.9 to 16.4 ms.
  • recognizer="tensorrt" matched ONNX Runtime's word F1 to one decimal for all five models. With YOLO26x-Text it read 322 of 32,022 words differently from ONNX Runtime, and 160 of 32,019 differently between two runs with separately built engines; ONNX Runtime repeated all 32,022.

Dependencies and Licenses#

ComponentRequiredRoleLicense
UltralyticsYesYOLO detection, crop geometry, and result orchestrationAGPL-3.0
ONNX RuntimeFor all but callables and "tensorrt" on NVIDIA GPUsRecognition runtime, 1.26+ on Python 3.11+MIT
PP-OCRv6 mediumFor "paddleocr" and "tensorrt"Recognition weights from the Ultralytics assets releaseApache-2.0
PP-OCRv5 mobileFor a PP-OCRv5 language model nameLanguage recognition weights from the Ultralytics assetsApache-2.0
TensorRTOnly for recognizer="tensorrt"FP16 PP-OCRv6 engine on NVIDIA GPUs, instead of ONNX RuntimeNVIDIA proprietary
Custom callableNoUser-owned recognition integrationDefined by the backend

PP-OCRv6 and PP-OCRv5 weights download on first use. Review the model card, such as PP-OCRv6 medium or Korean PP-OCRv5 mobile, and redistribution terms before packaging or deploying them. Each ONNX model names its source card in its source metadata. Custom checkpoint licenses are separate.

FAQ#

  • Yes. Pass a callable as recognizer and return (text, confidence) for each BGR crop. See Use a Custom Recognizer for the input and output contract.

  • Yes, with a language model. The default PP-OCRv6 covers Chinese, Japanese, and Latin-script languages, so pass recognizer="cyrillic_PP-OCRv5_mobile_rec", "korean_PP-OCRv5_mobile_rec", or "arabic_PP-OCRv5_mobile_rec". YOLO26-Text detects words in any script. See Read Other Scripts.

  • Yes, at any rotation. OCR finds the page's text direction from the word boxes, crops words upright in that frame, and reads the widest words both ways to settle 0° or 180°, so pages turned 90° or upside down return the same text in the same reading order. See How Scene Text OCR Works.

  • No. OCR treats every input image independently, without track IDs or cached recognition. Process each video frame as a separate input when frame-by-frame OCR is required.

  • Yes, on NVIDIA GPUs: solutions.OCR(recognizer="tensorrt") lowered the full call from 106.3 ms to 57.7 ms per image with YOLO26x-Text in the benchmarks, at the same word F1 to one decimal and with 322 of 32,022 words read differently from ONNX Runtime. The first run builds an FP16 TensorRT engine (about 30 seconds) and caches it next to the PP-OCRv6 model for each TensorRT version and GPU architecture. The default recognizer="paddleocr" builds nothing and starts in about a second. Without an NVIDIA GPU, "tensorrt" runs PP-OCRv6 on ONNX Runtime.

  • Start with the defaults, YOLO26x-Text with PP-OCRv6. On an NVIDIA GPU, pass recognizer="tensorrt" for lower latency at the same word F1, and use YOLO26n-Text when the download size matters more than accuracy. Choose a Model and Recognizer gives the measured trade-offs.

  • Pass your license plate detector as model: solutions.OCR(model="path/to/license-plate-detector.pt") reads the text inside every detected box and returns it in result.texts, with no manual cropping. See Read Text Inside Your Own Detections.

  • You can export the YOLO detector with the normal Export mode, but the PP-OCRv6 or custom recognizer is not embedded in the ONNX, TensorRT, or other detector artifact. Deploy the exported detector and recognition runtime as separate components, or keep this Python composition layer.

Comments

Ask a question, share your results, or help someone else.