Text Extractor from Image
Extract text from images with Tesseract OCR. Built by Noorullah Zamindar β original Flask app and notebook at NoorullahZamindar-007/Text-Extractor-From-Image.
This is a classical OCR pipeline, not a trained model. There are no
weights and no training data. The "model" is Tesseract OCR
(tesseract-ocr, language data eng), driven by the code in
ocr_extractor.py, which is the OCR logic from the original app.py and
notebook, kept unchanged in behaviour and packaged so it can run without
the Flask web server.
How it works
- Open the image and run
pytesseract.image_to_stringwith the project's config (-l eng --oem 3 --psm 6, from the notebook). - Optionally first run the notebook's preprocessing helpers β grayscale, median denoise, Otsu threshold, deskew β for noisy or rotated scans.
- Optionally get word-level boxes and confidences
(
pytesseract.image_to_data), or highlight words matching a pattern, as the notebook demonstrates.
Requirements
Tesseract itself must be installed on the machine β it is a system program, not a Python package:
sudo apt install tesseract-ocr # Debian / Ubuntu
pip install -r requirements.txt
How to use
python ocr_extractor.py samples/dickens.png
python ocr_extractor.py photo.png --preprocess # noisy scan
python ocr_extractor.py photo.png --preprocess --deskew # rotated scan
from ocr_extractor import extract_text, extract_text_preprocessed, word_data
print(extract_text("photo.png"))
print(extract_text_preprocessed("scan.png")) # grayscale + denoise + Otsu
print(word_data("photo.png")) # word text, confidence, boxes
Measured results
Measured 17 Nov 2026 with evaluate.py (included), Tesseract 5.3.4,
on the sample images in samples/. CER = character error rate, WER =
word error rate, both with whitespace collapsed on both sides
(case-sensitive, punctuation kept). Lower is better; 0.0000 is perfect.
| Sample | Default CER | Default WER | Preprocessed CER | Preprocessed WER |
|---|---|---|---|---|
| text_styles (676Γ371, the repo's sample image) | 0.0000 | 0.0000 | 0.1059 | 0.2222 |
| text_styles_small (300Γ150, the notebook's exact input) | 0.0000 | 0.0000 | 0.6118 | 1.0741 |
| dickens (700Γ440, "A Tale of Two Cities" opening) | 0.0278 | 0.0417 | 0.0278 | 0.0417 |
| synthetic_clean (rendered, ground truth known) | 0.0000 | 0.0000 | 0.0132 | 0.0833 |
| synthetic_rotated (same render, rotated 3Β°) | 0.0000 | 0.0000 | 0.0199 | 0.0833 |
- The module reproduces the notebook's printed output exactly on the notebook's own input (300Γ150): all five lines, word for word β the same text the notebook printed in cell 6.
- The Dickens sample's only errors are the trailing
...: all 24 words are recognised; the ellipsis adds 3 characters (CER 0.0278) and makesfoolishness...count as one wrong word (WER 0.0417). - The 3Β°-rotated synthetic image is read perfectly even without deskew β Tesseract tolerates small rotations on its own.
- The app's exact call (
image_to_stringwith no config, as inapp.py) also reads the text_styles sample perfectly.
Limitations β read before using
- Preprocessing can make clean images worse, not better. On the clean samples above, grayscale + denoise + Otsu thresholding raised the error rate β it destroys the outlined text in the sample (CER 0.1059) and wrecks the small 300Γ150 image entirely (CER 0.6118). Use the default (no preprocessing) on clean images, and preprocessing only on genuinely noisy or dirty scans. Deskew made no difference on any sample here.
- English only. The config is
-l eng; other languages need their Tesseract language data installed andlangchanged. - Printed text only. Handwriting, very small text, and low-contrast or skewed photos will read badly or not at all β Tesseract is an OCR engine, not a vision model, and it has no layout understanding.
- No confidence threshold is applied.
extract_textreturns whatever Tesseract produces, including wrong guesses on blurry input. Useword_dataand filter on theconffield if you need to distrust low-confidence words. - The sample images are a public-domain-style text sample and the opening of A Tale of Two Cities β no personal data.
Files
ocr_extractor.pyβ the OCR pipeline (library + CLI), from the originalapp.pyand notebookevaluate.pyβ reproduces every number in the table abovemetrics.jsonβ the measured resultsrequirements.txtβ pytesseract, opencv-python-headless, numpy, Pillowsamples/β the repo's two sample images, the notebook-size version, and two synthetic renders with known ground truth
Source
Original project: NoorullahZamindar-007/Text-Extractor-From-Image (Flask web app + Jupyter notebook). The full Flask app with its HTML templates lives there; this repo ships the OCR logic as a reusable module so it can be run without the web server.