Seven segment OCR: Tesseract, ssocr and Apple Vision, tested
23 of 47
displays read exactly, with a clean-up script and 7seg
A display model beats the English one
We cut 47 displays from 39 free photos on Wikimedia Commons. Each crop holds one reading.
| Run | Exact | Digits |
|---|---|---|
| prep.py, 7seg; --thick if blank | 23 | 72.5% |
| prep.py, 7seg | 20 | 54.0% |
| prep.py, ssd | 15 | 55.6% |
| prep.py, ssocr | 12 | 60.3% |
| ssocr, Home Assistant, -T | 11 | 60.8% |
| letsgodigital | 9 | 37.6% |
| Apple Vision | 7 | 41.8% |
| eng, Tesseract defaults | 1 | 8.5% |
| ssocr, Home Assistant, crop set | 0 | 7.9% |
| ssocr, Home Assistant defaults | 0 | 0.0% |
Exact means every digit, point and minus sign right. Colons do not count. Digits is the share of digits read right, in order.
No run read 13 of the 47 displays exactly.
The command: clean up, then 7seg
python3 -m venv .venv && . .venv/bin/activate && pip install pillow
curl -LO https://raw.githubusercontent.com/Shreeshrii/tessdata_ssd/e493a10a4bf81632506cf24ba99d83854afff9f6/7seg.traineddata
mkdir -p tessdata && mv 7seg.traineddata tessdata/
python3 prep.py display.jpg clean.png --light
tesseract clean.png stdout --tessdata-dir tessdata -l 7seg --psm 7 \
-c tessedit_char_whitelist=0123456789.-:
Crop to the digits first. Use --light for light digits on dark (LED, VFD).
No digits? Run prep.py again with --thick added, then the same tesseract line. That took us from 20 to 23.
The 7seg model is 11.4 MB. Its maker found it better than the newer ssd model on a small sample of real photos. We did too, on exact reads.
prep.py: dark on white, 100 px tall, Otsu
"""Make a seven-segment crop easy to read: dark digits on white, 100 px tall, black and white (Otsu).
Run: python3 prep.py in.jpg out.png [--light] [--thick]
--light light digits on a dark display (LED, VFD)
--thick grow the strokes, so the gaps between segments close
"""
import sys
from PIL import Image, ImageFilter, ImageOps
def otsu(im):
h = im.histogram()
total, every = sum(h), sum(i * c for i, c in enumerate(h))
best = t = w0 = s0 = 0
for i, c in enumerate(h):
w0, s0 = w0 + c, s0 + i * c
w1 = total - w0
if w0 and w1:
between = (s0 / w0 - (every - s0) / w1) ** 2 * w0 * w1
if between > best:
best, t = between, i
return t
def prep(src, dst, light=False, thick=False):
im = Image.open(src).convert("L")
if light:
im = ImageOps.invert(im)
im = im.resize((max(1, round(im.width * 100 / im.height)), 100), Image.LANCZOS)
t = otsu(im)
out = ImageOps.expand(im.point(lambda v: 255 if v > t else 0), 20, fill=255)
if thick:
out = out.filter(ImageFilter.MinFilter(5))
out.save(dst)
return im
if __name__ == "__main__":
prep(sys.argv[1], sys.argv[2], "--light" in sys.argv, "--thick" in sys.argv)
LCDs were hardest for 7seg
| Kind | Displays | 7seg | ssocr |
|---|---|---|---|
| LED | 25 | 14 | 8 |
| LCD | 9 | 3 | 3 |
| VFD | 13 | 6 | 1 |
7seg is the two-step command. ssocr is ssocr after prep.py, and VFDs were its hardest.
What to watch for
- A frame edge at the side of the crop reads as an extra one. We cut 8 crops again, tighter. Loose, 4 of them got an extra one at an end in some runs.
- The decimal point is weak. Of 20 displays with a point, the two-step command got the digits right on 12.
- On 4 of those 12, it got the point wrong: lost, moved or added.
- Alone, 7seg wrote no digit on 19 displays, most of its misses. With --thick as the second try, 9.
- When 7seg wrote digits, it was right on 20 of 28 displays.
ssocr and Home Assistant
Home Assistant's Seven Segments OCR runs ssocr. Its default crop has zero width and height. That gave an empty reading on all 47 displays.
With the crop set and other defaults kept, it read 0 of 47.
Add -T to extra_arguments, and
-f white -b black for light digits: 11 of 47.
image_processing:
- platform: seven_segments
x_position: 120
y_position: 80
width: 300
height: 90
extra_arguments: -T -f white -b black
source:
- entity_id: camera.meter
Put your own crop in pixels. On its own with -d -1 (any digit count), ssocr read 3 of 47, and 12 after prep.py.
How we ran it
- 39 photos from Wikimedia Commons, in 4 categories of displays and LED watches: 25 CC BY-SA, 9 CC BY, 5 public domain. We show none of them.
- We cut 53 displays out of the photos, one box each. Two AI readers read each crop on their own. We kept the 47 where both wrote the same reading.
- Tesseract runs read one line (--psm 7), except eng with Tesseract defaults. The whitelist allows only digits, point, minus and colon.
- Scores drop colons. Digits is the longest common subsequence of digits, over all reference digits.
- Tesseract 5.5.4 and ssocr 2.26.0 from Homebrew. Apple Vision: VNRecognizeTextRequest, accurate, no language correction, macOS 26.6.
- Models: eng from tessdata_fast and tessdata_best 4.1.0. 7seg, ssd and ssd_int from Shreeshrii/tessdata_ssd. letsgodigital from arturaugusto/display_ocr, a legacy model, run with --oem 0.
- Licenses: Tesseract and tessdata_ssd are Apache-2.0, ssocr is GPL-3.0, letsgodigital is GPL-2.0.
- The Home Assistant rows run the exact command its integration builds, from its source on GitHub.
- We tried 35 runs in all, with gray, Sauvola and raw versions. The table shows 10.
- One thread a run, 2 crops at a time, at low priority, while other jobs ran.
Scanned pages to text, no install
Run it yourself. Our Apify Actor turns a scanned PDF into Markdown or text. $0.006 a scanned page. It is built for documents, not display photos.
Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.
Questions people ask
Can Tesseract read seven-segment displays?
Not with its stock English model at default settings: it read 1 of our 47 displays. With our prep.py and the 7seg model from tessdata_ssd, it read 23.
What is the best free seven segment OCR?
On our 47 displays, Tesseract's 7seg model after prep.py read 23 exactly. ssocr after prep.py read 12, and Apple Vision 7.
Why does Home Assistant's Seven Segments OCR read nothing?
Its default crop has zero width and height. Set x_position, y_position, width and height to the digits. In extra_arguments, add -T, and -f white -b black for light digits.
Why does OCR add a 1 to my reading?
A frame edge in the crop reads as a one. Cut the crop tight to the digits. Of 8 crops we cut again, 4 got an extra one in some runs when loose.
Can OCR read the decimal point on a display?
Not well. Of 20 displays with a point, the two-step command got the digits right on 12, and got the point wrong on 4 of those.