| name | ocr-recognition |
| description | OCR (Optical Character Recognition) for extracting text from images.
Use when user needs to: (1) Extract text from screenshots, (2) Recognize captcha codes,
(3) Read text from photos, (4) Convert scanned PDFs to text, (5) Identify numbers/letters from images.
Supports Tesseract OCR with Docker, Python OpenCV preprocessing, and decision flow for captcha recognition.
|
OCR Recognition
Quick Start
1. Check System Tesseract
which tesseract
tesseract --version
2. Docker Alternative (No Install Required)
docker pull minidocks/tesseract:latest
wget -L -O /tmp/eng.traineddata https://github.com/tesseract-ocr/tessdata/raw/main/eng.traineddata
mkdir -p /tmp/tessdata
mv /tmp/eng.traineddata /tmp/tessdata/
docker run --rm \
-v /path/to/image.png:/image.png:ro \
-v /tmp/tessdata:/usr/share/tessdata:ro \
minidocks/tesseract:latest \
tesseract /image.png stdout
3. Digits Only (for captcha)
docker run --rm \
-v /path/to/captcha.png:/captcha.png:ro \
-v /tmp/tessdata:/usr/share/tessdata:ro \
minidocks/tesseract:latest \
tesseract /captcha.png stdout --psm 6 -c tessedit_char_whitelist=0123456789
Decision Flow
See references/decision-flow.md for complete decision tree.
TL;DR
- System has tesseract? → Use it
- No sudo? → Use Docker
- Poor results? → Try preprocessing (see scripts/)
- Still poor (especially captcha)? → Use commercial solution (see references/commercial-solutions.md)
Common Tasks
Debug Steps (Always Run First)
file your_image.png
docker --version
ls -la /tmp/tessdata/
file /tmp/tessdata/eng.traineddata
Extract text from screenshot
docker run --rm \
-v screenshot.png:/image.png:ro \
-v /tmp/tessdata:/usr/share/tessdata:ro \
minidocks/tesseract:latest tesseract /image.png stdout
Recognize captcha (digits only)
See references/captcha-guide.md for detailed captcha strategies.
Chinese text recognition
mkdir -p /tmp/tessdata
wget -L -O /tmp/tessdata/chi_sim.traineddata https://github.com/tesseract-ocr/tessdata/raw/main/chi_sim.traineddata
docker run --rm \
-v image.png:/image.png:ro \
-v /tmp/tessdata:/usr/share/tessdata:ro \
minidocks/tesseract:latest tesseract /image.png stdout -l chi_sim
Scripts
Setup Tessdata Directory (One-time)
mkdir -p /tmp/tessdata
wget -L -O /tmp/tessdata/eng.traineddata https://github.com/tesseract-ocr/tessdata/raw/main/eng.traineddata
Preprocessing Pipeline
When OCR results are poor, use preprocessing:
python3 scripts/preprocess.py --input captcha.png --output processed.png --method otsu
Available methods: threshold, otsu, adaptive, morphology
Quick OCR Command
./scripts/ocr.sh image.png
Parameters Reference
PSM Modes
| PSM | Description | Best For |
|---|
| 3 | Fully automatic | Default |
| 6 | Assume single block | Captcha |
| 7 | Treat as single line | Single row |
| 8 | Treat as single word | Spaced chars |
| 10 | Character mode | Single char |
White list
-c tessedit_char_whitelist=0123456789
-c tessedit_char_whitelist=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
-c tessedit_char_whitelist=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
When to Use This Skill
- Extract text from screenshots
- Read captcha/verification codes
- Convert images to text
- Batch OCR processing
- Any image-to-text task