This project is an advanced OCR-based system designed to extract shipping label barcodes following the pattern:
<11+ digit barcode>_1_<1–3 letter suffix>
The system performs full-text scanning, applies multi-engine OCR fusion (Tesseract + EasyOCR), and uses heuristic repair logic to reconstruct barcodes even when OCR splits or distorts characters. The UI is built using Streamlit, and OpenCV handles the preprocessing pipeline. Extracted results are auto-saved into a unified JSON file.
- Python 3.8+
- Tesseract OCR installed
- Pip dependencies
git clone https://github.com/rakshit2010/ocr_task_solution.git
cd shipping-label-ocrpip install -r requirements.txtTypical requirements:
streamlit
opencv-python
numpy
pytesseract
easyocr
Download from: https://github.com/UB-Mannheim/tesseract/wiki
Add to PATH:
C:\Program Files\Tesseract-OCR
Or change the path in ocr_engine.py to your tesseract path
streamlit run app.pyUpload PNG/JPG/TIFF shipping label images.
Use the sidebar slider to adjust upscale factor.
Click:
- Scan all text and search for pattern
The system executes:
- Auto-rotation
- Enhancement + denoising
- Full-text OCR
- Heuristic reconstruction
- Pattern matching & engine fusion
- Extracted barcode is displayed at the bottom.
- Auto-saved to:
results/single_results.json
- Manual editing also allowed.
- Strong with numeric strings
- Offers orientation detection (OSD)
- Better for alphabetic suffixes
- Grayscale conversion
- CLAHE enhancement
- Non-local means denoising
- ×2 upscaling
- Sharpening
- Adaptive + Otsu thresholding
- Morphological cleanup
- Auto-orientation (Tesseract OSD + contour-based)
The system uses five extraction stages:
Tokens collected → normalized → deduplicated.
- Detects digit runs ≥ 11
- Extends digits from neighbors
- Extracts suffix candidates
Ensures:
- 11+ digits
_1- Optional 1–3 letter suffix
Handles split tokens.
Combines:
- Tesseract digits
- EasyOCR alphabetic suffix
Solution: Heuristic stitching + reconstruction + fusion.
Solution: Prefer EasyOCR for suffix detection.
Solution: Combine Tesseract OSD with contour-based correction.
Solution: Upscaling, sharpening, and advanced denoising.
Solution: Enforce strict 11+ digit rule.
- Integrate deep-learning OCR (PaddleOCR, TrOCR)
- YOLO-based barcode localization
- Automatic label region cropping
- Confidence scoring & heatmaps
- Batch processing mode
- Docker deployment
- Cloud API version