Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Automated Vision Inspection System for Heat Codes on Metal Casts

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.

🚀 Quick Start

Web UI (Easiest)

# Run the interactive web interface
start_ui.bat

Then 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

Command Line

# 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

Jupyter Notebook

.\run.bat -m jupyter notebook notebooks/demo.ipynb

Architecture

The system consists of four main stages:

  1. Image Quality Assessment & Selection: Selects the best image from a batch based on quality metrics.
  2. Preprocessing: Normalizes images to remove reflections, noise, and geometric distortions.
  3. Core Deep Learning OCR: Detects and recognizes text characters in the images.
  4. Verification & Defect Detection: Compares recognized text with reference code and identifies defects.

Dataset

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

Installation

  1. Clone this repository
  2. Install dependencies: pip install -r requirements.txt
  3. Generate synthetic dataset: python scripts/generate_dataset.py
  4. Test the pipeline: python scripts/test_pipeline.py

Usage

Command Line

from src.pipeline import InspectionPipeline

pipeline = InspectionPipeline()
report = pipeline.inspect(images, reference_code)
print(report)

Jupyter Notebook

See notebooks/demo.ipynb for a complete example.

Pipeline Details

Stage 1: Image Quality Assessment

  • Calculates sharpness using Laplacian variance
  • Measures contrast using standard deviation
  • Selects image with highest combined score

Stage 2: Preprocessing

  • Converts to grayscale
  • Applies denoising (fastNlMeansDenoising)
  • Enhances contrast using CLAHE
  • Morphological cleaning

Stage 3: OCR

  • Uses EasyOCR for text detection and recognition
  • Supports alphanumeric characters

Stage 4: Verification

  • Normalizes text (uppercase, alphanumeric only)
  • Uses sequence matching for character-level comparison
  • Identifies deletions, insertions, and substitutions

Output Format

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
}

Project Structure

  • data/: Datasets and annotations
  • models/: Trained model files
  • src/: Source code
  • notebooks/: Jupyter notebooks for training and experimentation
  • scripts/: Utility scripts
  • tests/: Unit tests

Future Improvements

  • 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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages