Computer Vision

OCR Pipelines

Extracting text from unstructured images using two-stage detection and sequence recognition models.

🟡 intermediate5 min readvision
Optical Character Recognition (OCR) converts text images into machine-readable digital text strings. Industrial OCR pipelines combine two stages: Text Detection (locating bounding boxes or polygons around text using EAST or DBNet) and Text Recognition (converting cropped text images into characters using CRNN + CTC Loss or Vision Transformer Decoders like TrOCR). Connectionist Temporal Classification (CTC) loss enables sequence training without explicit character-level alignment annotations.

Industrial 2-Stage OCR Pipeline

  INPUT SCENE IMAGE            STAGE 1: TEXT DETECTION           STAGE 2: TEXT RECOGNITION
  (Receipt / Street Sign)      (DBNet / EAST / PaddleOCR)        (CRNN + CTC / TrOCR)
  ┌──────────────────────┐     ┌──────────────────────┐          ┌─────────────────────────┐
  │  [ RECEIPT HEADER ]  │ ──► │ Crop Polygons:       │ ──►      │ Crop 1: "WALMART STORE" │
  │  [ ITEM 1: $12.99 ]  │     │ - Polygon 1 [x,y..]  │          │ Crop 2: "TOTAL $12.99"  │
  └──────────────────────┘     │ - Polygon 2 [x,y..]  │          └─────────────────────────┘
                               └──────────────────────┘          Output: Clean Text Json!

Stage 1: Text Detection (DBNet / Real-Time Detection)

Unlike standard object detection, scene text appears at arbitrary angles, curved shapes, and extreme aspect ratios.

DBNet (Real-time Scene Text Detection with Differentiable Binarization): Predicts probability maps and adaptive threshold maps, using a differentiable step function to output precise text boundary polygons directly.

Stage 2: Text Recognition (CRNN + CTC Loss)

Given a cropped text line image:

  Text Line Crop Image ──► [ CNN Feature Extractor ] ──► [ Map-to-Sequence ] ──► [ Bidirectional LSTM ] ──► CTC Loss

Connectionist Temporal Classification (CTC) Loss

In text recognition, annotators provide ground-truth text "CAT", but do NOT label where letter 'C' ends and 'A' starts in the image pixels.

CTC introduces a special Blank Token ($\epsilon$) and collapses repeated characters:

$$\text{Output Sequence: } \text{"C - C - - A - - T - T"} \xrightarrow{\text{Collapse Repeats & Blanks}} \text{"CAT"}$$

CTC computes the sum of probabilities over all valid aligned sequences using dynamic programming!

Modern Vision Transformer OCR (TrOCR)

TrOCR (Microsoft, 2021) replaces CNN-RNN-CTC pipelines with a pure Transformer Encoder-Decoder:

  Text Crop Image ──► [ ViT Image Encoder (Patches) ] ──► [ Transformer Text Decoder ] ──► "WALMART"
  1. Encoder: Pre-trained Vision Transformer (DeiT / BEiT) processes image patches.
  2. Decoder: Pre-trained Text Transformer (RoBERTa / GPT-2) generates text tokens autoregressively.

TrOCR achieves state-of-the-art accuracy on printed text, handwritten documents, and historical manuscripts.

Say this out loud

OCR pipelines combine Stage 1 Text Detection (DBNet) to crop text polygons and Stage 2 Text Recognition (CRNN or TrOCR) to transcribe images into text strings. CTC loss trains text recognition models without character-level pixel segment annotations by introducing blank tokens and collapsing repeated predictions. Modern systems like TrOCR use Vision Transformer encoders and text decoders for end-to-end transcription.

Follow-ups to expect

Check yourself

Question 1 of 3

What are the two core sequential stages in modern end-to-end Optical Character Recognition (OCR) systems?

More in Computer Vision

See all →
Image Augmentation Strategies5 minResizing, Normalization & Colour Spaces4 minResNet, EfficientNet & Friends5 min