How buiquangmanhhp1999/extract-information-from-identity-card works
Project Type and Purpose
• This is a backend service (no user-facing GUI) that exposes an HTTP API for extracting structured data from scanned identity-card images.
• It chains three machine-learning stages—corner detection, text detection, and OCR via a custom VietOCR model—and then outputs JSON.
Top-Level Components
A. API Layer (main.py + serve/serve_model.py or src/serve_model.py)
• Listens for HTTP POSTs with image payloads
• Parses requests, forwards images to the pipeline, returns JSON
B. Configuration Manager (src/config.py)
• Centralizes paths to model files and pipeline parameters
C. Corner Detection Module (src/detector/config_corner_detection + detector.py)
• Uses a TFLite model to find card corners
• Utils (image_utils.py) perform perspective warp/alignment
D. Text Detection Module (src/detector/config_text_detection + detector.py)
• Uses a separate TFLite model to locate text regions
E. Text Recognition Module (src/vietocr)
• Configuration files (base.yml, vgg-transformer.yml) select model architecture
• Model definitions (cnn.py, transformer.py, vgg.py) load weights
• Predictor (tool/predictor.py) runs OCR on each cropped region
• Optional translation (tool/translate.py) if needed
F. Merge & Post-processing (src/merged_model.py)
• Combines OCR results into structured fields (id, name, birth, address, home)
G. External Storage (samples folder for example images, downloaded weights in vietocr/config_text_recognition)
Data Flow & Interactions
1. Client HTTP POST → API Layer
2. API loads config → forwards image to Corner Detection
3. Corner Detection → aligned image
6. OCR outputs strings → Merge & Post-processing
7. Final JSON → API Layer → HTTP Response
Architectural Patterns & Principles
• Layered architecture: clear separation between API, ML detection, and OCR
• Modularity: each model lives in its own directory with configs, weights, and utilities
• Single responsibility: detector modules only detect, OCR module only recognizes, merge module only assembles results