This project implements an automated vision inspection system to check manually punched heat codes on metal casts. The system uses deep learning to detect defects in punched codes, comparing them against a reference ideal code.
# Run the interactive web interface
start_ui.batThen open http://localhost:8501 in your browser!
UI Features:
- 🎯 Drag & Drop image upload
- 📝 Text input for reference codes
- 📊 Interactive reports with charts and visualizations
- 🔍 Character-level analysis with defect highlighting
- 💾 Export results as JSON
- 🎨 Beautiful interface with real-time feedback
UI Preview:
- Sidebar: File upload and reference code input
- Main Panel: Image comparison (original vs processed)
- Results Cards: Quality score, pass/fail status, defect count
- Text Analysis: Reference vs predicted text comparison
- Defect Details: Expandable sections for each defect found
# Test with your own image
.\run.bat scripts/inspect_custom.py -i "your_image.jpg" -c "HEAT24ZB"
# Generate comprehensive report
.\run.bat scripts/generate_report.py.\run.bat -m jupyter notebook notebooks/demo.ipynbThe system consists of four main stages:
- Image Quality Assessment & Selection: Selects the best image from a batch based on quality metrics.
- Preprocessing: Normalizes images to remove reflections, noise, and geometric distortions.
- Core Deep Learning OCR: Detects and recognizes text characters in the images.
- Verification & Defect Detection: Compares recognized text with reference code and identifies defects.
Since no real dataset is available, we generate synthetic data that simulates:
- Punched text on metallic surfaces
- Various lighting conditions and reflections
- Geometric distortions
- Character defects and substitutions
- Clone this repository
- Install dependencies:
pip install -r requirements.txt - Generate synthetic dataset:
python scripts/generate_dataset.py - Test the pipeline:
python scripts/test_pipeline.py
from src.pipeline import InspectionPipeline
pipeline = InspectionPipeline()
report = pipeline.inspect(images, reference_code)
print(report)See notebooks/demo.ipynb for a complete example.
- Calculates sharpness using Laplacian variance
- Measures contrast using standard deviation
- Selects image with highest combined score
- Converts to grayscale
- Applies denoising (fastNlMeansDenoising)
- Enhances contrast using CLAHE
- Morphological cleaning
- Uses EasyOCR for text detection and recognition
- Supports alphanumeric characters
- Normalizes text (uppercase, alphanumeric only)
- Uses sequence matching for character-level comparison
- Identifies deletions, insertions, and substitutions
The system returns a detailed JSON report:
{
"reference_code": "HEAT24ZB",
"predicted_text": "HEAT2AZB",
"normalized_predicted": "HEAT2AZB",
"normalized_reference": "HEAT24ZB",
"image_quality_score": 0.85,
"is_correct": false,
"defects": [
{
"type": "substitution",
"position": 5,
"expected": "4",
"found": "A"
}
],
"defect_count": 1
}data/: Datasets and annotationsmodels/: Trained model filessrc/: Source codenotebooks/: Jupyter notebooks for training and experimentationscripts/: Utility scriptstests/: Unit tests
- Train custom CNN models for image quality assessment
- Implement specialized OCR models for punched text
- Add defect classification for common confusion patterns
- Support for multiple reference codes
- Real-time processing capabilities