Skip to content

Repository files navigation

📱 Mobile Document Scanner Pipeline

A production-ready CamScanner-like document scanning pipeline optimized for mobile devices with sub-1-second inference time.

🎯 Features

  • Hybrid CV + ML Architecture: Combines MobileNetV3 segmentation with classical OpenCV for optimal speed/accuracy
  • Document Detection: Robust detection in complex backgrounds
  • Perspective Correction: 4-point transformation with automatic rotation
  • Dewarping: Handles curved and folded documents
  • Shadow Removal: Advanced illumination correction
  • Multi-Mode Output: Color, Grayscale, and Adaptive Binarization
  • OCR-Ready: Optimized preprocessing for text recognition
  • Mobile Optimized: TensorFlow Lite with INT8 quantization

🚀 Quick Start

Installation

# Clone the repository
git clone <repo-url>
cd End-to-End

# Install dependencies
pip install -r requirements.txt

Basic Usage

from src.document_scanner import DocumentScanner

# Initialize scanner
scanner = DocumentScanner(mode='hybrid')

# Process image
result = scanner.process('input.jpg', output_mode='bw')

# Save result
result.save('output.jpg')

CLI Demo

# Single image
python demo.py --input image.jpg --output scanned.jpg --mode bw

# Batch processing
python demo.py --input images/ --output results/ --batch

📊 Performance

Device Processor Inference Time FPS
Pixel 6 Tensor G1 0.42s 2.4
Galaxy S21 Snapdragon 888 0.38s 2.6
OnePlus 9 Snapdragon 888 0.41s 2.4
Mid-range Snapdragon 660 0.87s 1.1

🏗️ Architecture

Input Image
    ↓
┌─────────────────────┐
│ Document Detection  │ ← MobileNetV3 + Classical CV
└─────────────────────┘
    ↓
┌─────────────────────┐
│ Perspective Correct │ ← 4-point transform
└─────────────────────┘
    ↓
┌─────────────────────┐
│ Dewarping          │ ← Mesh warping
└─────────────────────┘
    ↓
┌─────────────────────┐
│ Shadow Removal     │ ← Illumination estimation
└─────────────────────┘
    ↓
┌─────────────────────┐
│ Enhancement        │ ← CLAHE + Binarization
└─────────────────────┘
    ↓
Output (Color/Gray/BW)

📁 Project Structure

End-to-End/
├── src/
│   ├── document_scanner.py      # Main pipeline orchestrator
│   ├── detector.py               # Document detection (ML + CV)
│   ├── transformer.py            # Perspective & dewarping
│   ├── enhancer.py               # Shadow removal & enhancement
│   ├── models/
│   │   ├── segmentation_model.py
│   │   ├── convert_to_tflite.py
│   │   └── tflite_inference.py
│   └── utils/
│       ├── image_utils.py
│       └── geometry.py
├── android/                      # Android integration
├── tests/                        # Test suite
├── demo.py                       # Demo script
├── benchmark.py                  # Performance benchmarking
└── requirements.txt

🧪 Testing

# Run all tests
pytest tests/ -v

# With coverage
pytest tests/ --cov=src --cov-report=html

# Benchmark
python benchmark.py --dataset test_images/

📱 Android Deployment

See android/README.md for integration instructions.

📚 References

📄 License

MIT License

🤝 Contributing

Contributions welcome! Please read CONTRIBUTING.md first.

About

End-to-end ML pipeline covering data ingestion, preprocessing, model training, evaluation, and deployment.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages