I run a visa agency in Bali. Most of what we handle comes as screenshots: a booking confirmation someone forwarded from WhatsApp, a flight reference, a payment receipt with an order ID. The prose on those screenshots is easy to read. The problem is the short codes, because a wrong code is worse than no code at all.

I also maintain an OCR Actor on Apify, Image to Text. It runs Tesseract inside the container and returns the text, a page confidence and, if you ask, every word with its own confidence and pixel box. I wanted to know how far I could trust it on identifiers, so I made a test I could check against an exact answer.

Test 1: a normal screenshot, light and dark

I started with an easy case: four lines of the kind of text you see on a failed-payment screen, rendered with ImageMagick in DejaVu Sans at 11, 16 and 24 px. Each size got a light version (near-black on white) and a dark-mode version (light grey on #1e1e1e):

Payment failed: card declined (code 51) Order #48213 - 2 items - total 1,590.00 USD Retry in 30 seconds or use another card. Reference A7F-22Q9, keep it for support. 

All six went in one run as base64, with word boxes on:

Size Light: page confidence Dark: page confidence What went wrong
11 px 88.9 87.9 A7F-22Q9 → A7F-2209 (word confidence 44 / 45)
16 px 94.3 93.3 lost the full stop after "card", no word below 80
24 px 95.0 95.0 none: 29 of 29 words exact

Two things surprised me. First, dark mode made almost no difference: about one point of confidence and the same mistakes. I had been converting dark screenshots to light ones before OCR, and that step was doing nothing.

Second, every sentence word at 11 px was right. The one word that broke was the reference code, and it broke on the Q. That made me want a harder test.

Test 2: eight codes made of look-alikes

I wrote eight lines of codes made almost entirely of characters that look alike in a sans-serif font. These are adversarial on purpose. Real booking systems often leave ambiguous characters out of their alphabets, but plenty don't, and order numbers from small shops are anything at all.

Booking ref: QX7O-0L1I Voucher: B8S5-Z2G6 Ticket: 0OQD-9QG8 Order ID: Il1|-7T1L Invoice: 5SBB-8Z2Z Tracking: RN4Q-0O0D Seat: 1I-L1 / 11B PNR: ZQ8B0S 

I rendered it at 11 px (174 × 153 pixels, the size of a cropped phone screenshot) and at 16 px (230 × 193). I also made a third version: the 11 px image upscaled 3x with a Lanczos filter (522 × 459). No new information, just more pixels per letter.

Truth 11 px 16 px 11 px upscaled 3x
QX7O-0L1I QX70-OL11 (58) QX70-OL1I (39) QX70-OL1I (63)
B8S5-Z2G6 BBS5-22G6 (28) ✅ (90) ✅ (90)
0OQD-9QG8 0000-3068 (76) OOQD-9QG8 (80) OOQD-9QG8 (66)
`Il1\ -7T1L` `I2\ -7T1L` (0)
5SBB-8Z2Z 5SBB-8222 (55) 5SBB- + 8Z2Z, split in two ✅ (84)
RN4Q-0O0D RN4Q-000D (82) line missing RN4Q-000D (92)
1I-L1 / 11B 11/118 (0) line missing ✅ (76, 54, 54)
ZQ8B0S ZQBBOS (70) ZQ8BOS (63) ZQ8BOS (45)
Exact codes 0 of 8 1 of 8 (+1 split) 3 of 8
Page confidence 69.4 79.2 80.8

The numbers in brackets are Tesseract's per-word confidence, 0 to 100.

At 11 px every code was wrong

The labels ("Booking", "Invoice:", "Tracking:") came back at 73 to 95. Every code was wrong. Some mistakes were large: 0OQD-9QG8 became 0000-3068, so three characters changed in the second half alone.

At 16 px two lines disappeared

This is the one that would hurt in production. The 16 px image is bigger and sharper, and its page confidence went up from 69.4 to 79.2. But the Tracking and Seat lines are simply gone. There is no error and no low-confidence placeholder. The row says status: "ok" with 15 words instead of 20. If your code takes the first match for "Tracking:", it finds nothing and moves on, as if the screenshot had no tracking number in it.

When I counted lines against the source I found the gap at once. Without a source to compare against, I would not have.

Upscaling helped, and the worst miss scored highest

The 3x upscale brought both lost lines back and got three codes right. It needs one line of ImageMagick and costs the same per image, so I now do it to every small screenshot before OCR.

Now look at the Tracking row. RN4Q-0O0D came back as RN4Q-000D at all three sizes. On the upscaled image that wrong word scored 92, the highest of any code on the page. Meanwhile the three correct tokens on the Seat line scored 76, 54 and 54.

So per-word confidence did not separate right from wrong here. A filter at 80 would have kept the wrong tracking number and dropped the correct seat. Tesseract's confidence tells you how cleanly a shape matched a letter, and in this font a capital O and a zero are nearly the same shape. Both readings are confident. Only one is true.

What I do with codes now

1. Upscale small screenshots before OCR. If the text is under roughly 15 px tall, enlarge it 2–3x:

convert small.png -filter Lanczos -resize 300% big.png 

2. Count lines, not just confidence. If you know a confirmation screen has eight labelled fields, check that all eight labels came back. A missing line was the only silent failure in my tests, and a confidence threshold can't catch it.

3. Treat codes as candidates and check them against the source of truth. If you have the list of valid booking references, or the code has a checksum, generate the look-alike variants and keep the one that exists:

from itertools import product LOOKALIKE = {"0": "0O", "O": "O0", "1": "1Il", "I": "I1l", "l": "lI1", "8": "8B", "B": "B8", "2": "2Z", "Z": "Z2", "5": "5S", "S": "S5"} def candidates(code, limit=4096): pools = [LOOKALIKE.get(ch, ch) for ch in code] for i, combo in enumerate(product(*pools)): if i >= limit: break yield "".join(combo) def resolve(ocr_code, known): hits = {c for c in candidates(ocr_code) if c in known} return hits.pop() if len(hits) == 1 else None # 0 or 2+ hits: a human looks known = {"RN4Q-0O0D", "QX7O-0L1I"} print(resolve("RN4Q-000D", known)) # RN4Q-0O0D 

A code with many ambiguous positions has many variants: RN4Q-000D has 8, 0000-3068 has 64. That works when the set of valid codes is small. If two variants both exist, send the image to a person.

4. Don't fix codes with a spell-checker or a language model. "Fixing" ZQ8BOS into something that looks more like a word is how a correct-looking wrong code ends up in a database.

Calling it

From the shell, with a public URL:

curl -X POST "https://api.apify.com/v2/acts/lergassy~image-to-text/run-sync-get-dataset-items?token=$APIFY_TOKEN" \ -H "Content-Type: application/json" \ -d '{"urls": ["https://example.com/confirmation.png"], "language": "eng", "includeWordBoxes": true}' 

From Python with local files, which is how I ran these tests (nothing to host):

import base64 from apify_client import ApifyClient files = [{"fileName": n, "data": base64.b64encode(open(n, "rb").read()).decode()} for n in ["codes-11.png", "codes-16.png", "codes-11-x3.png"]] run = ApifyClient(TOKEN).actor("lergassy/image-to-text").call(run_input={ "base64Files": files, "urls": [], "language": "eng", "includeWordBoxes": True, "includePages": False, }) for row in ApifyClient(TOKEN).dataset(run["defaultDatasetId"]).iterate_items(): print(row["fileName"], row["status"], row.get("confidence")) for w in row.get("words", []): print(f' {w["text"]:<12} {w["confidence"]:>5} at ({w["left"]},{w["top"]})') 

Each file gives one row: text, wordCount, page confidence, and words with text, confidence, left, top, width and height. The six-image run in test 1 took about six seconds end to end. Pricing is per image that returns text: $0.004.

When this is the wrong tool

  • Codes that must be exactly right, with no list to check against. Use the barcode or QR code on the document if there is one. Otherwise have a person type it.
  • Handwriting. Tesseract doesn't read it reliably.
  • Phone photos of screens or receipts taken at an angle, with glare. Expect much lower scores than these clean renders, and expect lines to go missing.
  • You need a character whitelist (for example "only A–Z and 2–9"). The Actor doesn't expose Tesseract's whitelist settings. Validate afterwards, as above.

The short version: OCR handled the sentences on these screenshots well, but not the codes. When characters look alike, the engine can be both confident and wrong, and a missing line produces no error at all. Check codes against something you trust, and check that every line you expected is there.

If you want to repeat this on your own screenshots, Image to Text accepts base64, so the test files never have to leave your machine except in the API call itself.