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

  1. Open the image and run pytesseract.image_to_string with the project's config (-l eng --oem 3 --psm 6, from the notebook).
  2. Optionally first run the notebook's preprocessing helpers β€” grayscale, median denoise, Otsu threshold, deskew β€” for noisy or rotated scans.
  3. 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 makes foolishness... 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_string with no config, as in app.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 and lang changed.
  • 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_text returns whatever Tesseract produces, including wrong guesses on blurry input. Use word_data and filter on the conf field 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 original app.py and notebook
  • evaluate.py β€” reproduces every number in the table above
  • metrics.json β€” the measured results
  • requirements.txt β€” pytesseract, opencv-python-headless, numpy, Pillow
  • samples/ β€” 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.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support