A powerful command-line tool for extracting Tamil text from images using advanced OCR technology with AI-powered validation and correction.
- Dual OCR Engines: Choose between
ocr_tamilandPaddleOCRfor optimal results - AI-Powered Validation: Qwen2.5 72B model corrects OCR errors and improves accuracy
- Multiple Preprocessing Techniques: 5 different image preprocessing methods
- Batch Processing: Process multiple images in a single command
- Confidence Assessment: Automatic quality evaluation of OCR results
- Beautiful Terminal Output: Color-coded, formatted results with clear visual hierarchy
OCR Engines Explained
- ocr_tamil (Default) What it is: A specialized OCR library specifically designed for Tamil script recognition. Strengths:
Optimized for Tamil Unicode characters Better handling of complex Tamil ligatures Lightweight and fast processing Pre-trained on Tamil documents
Best for:
Printed Tamil text Clear, high-contrast images Modern Tamil fonts Documents and books
Technical Details:
Uses deep learning models trained on Tamil datasets Includes text detection and recognition modules Handles diacritics and conjunct characters
- PaddleOCR What it is: An industrial-grade multilingual OCR system developed by Baidu, supporting 80+ languages including Tamil. Strengths:
Robust text detection in complex layouts Better performance on handwritten text Advanced angle correction capabilities Handles skewed or rotated text
Best for:
Complex document layouts Handwritten Tamil text Mixed Tamil-English documents Challenging lighting conditions
Technical Details:
Uses DB (Differentiable Binarization) for text detection CRNN (Convolutional Recurrent Neural Network) for recognition Built-in text angle classification Supports both GPU and CPU inference
- Python 3.12.8
- 4GB+ RAM recommended
- CPU-based processing (no GPU required)
Install all required libraries:
pip install -r requirements.txt-
Clone or download the repository
git clone https://github.com/100-multidisciplinary-projects/Text-Extractor cd Text-Extractor -
Install dependencies
pip install -r requirements.txt
-
Verify installation
python app.py image_name.jpg
Process a single image:
python app.py image.jpgProcess multiple images:
python app.py img1.jpg img2.jpg img3.pngSpecify OCR Engine:
python app.py image.jpg --engine paddleocrChoose Preprocessing Mode:
python app.py image.jpg --mode aggressiveEnable AI Validation:
python app.py image.jpg --api-key YOUR_OPENROUTER_KEY --aiCustom Output Directory:
python app.py image.jpg --output ./my_resultsShow Detailed Results:
python app.py image.jpg --mode auto --details| Argument | Short | Description | Default |
|---|---|---|---|
images |
- | Path(s) to input image file(s) | Required |
--output |
-o |
Output directory for results | ./ocr_output |
--engine |
-e |
OCR engine: ocr_tamil or paddleocr |
ocr_tamil |
--mode |
-m |
Preprocessing mode (see below) | auto |
--api-key |
-k |
OpenRouter API key for AI validation | None |
--ai |
- | Enable AI validation (requires API key) | Disabled |
--details |
-d |
Show detailed preprocessing results | Disabled |
--no-color |
- | Disable colored terminal output | Disabled |
The application offers 5 preprocessing methods optimized for different image types:
- Uses the raw image as-is
- Best for: High-quality scanned documents with clear text
- When to use: Modern digital images, screenshots with crisp text
- Denoising + CLAHE enhancement + Adaptive thresholding
- Best for: Printed text, books, documents
- When to use: Standard quality scans, printed materials
- Techniques:
- Fast Non-Local Means Denoising
- CLAHE (Contrast Limited Adaptive Histogram Equalization)
- Gaussian adaptive threshold
- Heavy denoising + Enhanced CLAHE + Morphological operations
- Best for: Handwritten text, faint text, low-quality images
- When to use: Old documents, faded text, poor lighting
- Techniques:
- Aggressive denoising (h=30)
- Mean adaptive threshold
- Morphological closing to connect broken characters
- Inverted threshold for dark backgrounds
- Best for: Dark backgrounds with light text (e.g., blackboards, dark themes)
- When to use: Light text on dark background, inverted images
- Techniques:
- Binary inverse thresholding
- Morphological opening to remove noise
- Elliptical structuring element
- Automatic threshold calculation using Otsu's method
- Best for: Images with clear contrast and bimodal histograms
- When to use: High-contrast images, clear separation between text and background
- Techniques:
- Gaussian blur for noise reduction
- Otsu's automatic thresholding
- No morphological operations (preserves original structure)
When using --mode auto, the application:
- Runs all 5 preprocessing methods
- Saves each preprocessed image
- Uses the "Original" method for final output
- Displays all results if
--detailsis enabled
- Corrects OCR recognition errors
- Fixes spelling mistakes in Tamil text
- Ensures proper grammar and sentence structure
- Preserves the original meaning
-
Get an API Key:
- Sign up at OpenRouter.ai
- Get your API key from the dashboard
-
Use AI Validation:
python app.py image.jpg --api-key YOUR_KEY --ai
-
Output:
- Shows both OCR-extracted text and AI-corrected text
- Saves both versions to the result file
The application automatically evaluates OCR quality:
- Excellent (80%+): High-quality recognition, minimal errors expected
- Good (65-79%): Reliable recognition, minor errors possible
- Fair (50-64%): Acceptable recognition, review recommended
- Poor (30-49%): Low quality, significant errors likely
- Very Poor (<30%): Very low quality, manual review required
Assessment factors:
- Text length (longer text = more reliable)
- Character quality (ratio of valid characters)
- Image clarity (Laplacian variance)
For each processed image, the application creates:
ocr_output/
βββ image_name/
βββ image_name_original.png # Original preprocessing
βββ image_name_standard.png # Standard preprocessing
βββ image_name_aggressive.png # Aggressive preprocessing
βββ image_name_inverted.png # Inverted preprocessing
βββ image_name_otsu.png # Otsu preprocessing
βββ image_name_result.txt # Final text results
- Image metadata (filename, size)
- OCR engine used
- Preprocessing method applied
- Confidence score
- Character count
- OCR extracted text (formatted)
- AI-corrected text (if AI validation was enabled)
python app.py document.jpgOutput: Basic OCR with standard preprocessing, results in ./ocr_output/
python app.py old_manuscript.jpg --mode aggressive --engine paddleocrBest for: Old documents, faded text
python app.py handwritten.jpg --api-key sk-or-v1-xxxxx --ai --mode auto --detailsBest for: Maximum accuracy with error correction
python app.py *.jpg --output ./batch_results --mode standardBest for: Processing multiple images at once
python app.py blackboard.jpg --mode invertedBest for: Light text on dark backgrounds
-
Image Quality:
- Use high-resolution images (300 DPI or higher for scans)
- Ensure good lighting and minimal shadows
- Avoid blurry or out-of-focus images
-
Choosing OCR Engine:
- ocr_tamil: Faster, good for standard text
- paddleocr: More accurate for complex layouts
-
Preprocessing Selection:
- Not sure? Use
--mode autoto try all methods - Printed text: Use
standardororiginal - Handwritten/faded: Use
aggressive - Dark backgrounds: Use
inverted - High contrast: Use
otsu
- Not sure? Use
-
AI Validation:
- Significantly improves accuracy
- Essential for handwritten text
- Requires internet connection
- Uses OpenRouter API (costs apply)
For issues, questions, or feature requests:
- Check the troubleshooting section
- Review command-line help:
python app.py --help - Refer to library documentation:
- Resizing: Images > 2000px are scaled down
- Denoising: Fast Non-Local Means algorithm
- Enhancement: CLAHE for contrast improvement
- Binarization: Adaptive or Otsu thresholding
- Morphology: Opening/closing operations (method-dependent)
Input Image β Preprocessing β OCR Engine β Text Extraction
β
Sentence Formatting
β
Confidence Assessment
β
AI Validation (optional)
β
Save Results & Display
Happy OCR Processing! π