Skip to content

About

AI-Powered Car Damage Detection System

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🚗 Advanced Car Damage Detector AI

An AI-powered system for automatic car damage detection using SAM + CNN + SSIM hybrid technology.

Car Damage Detection Example

Example: Before and after comparison with AI-detected damage highlighting

✨ Key Features

  • 🔍 Multi-Stage AI Detection: Combines SAM segmentation, CNN classification, and SSIM analysis
  • 📸 Before/After Comparison: Automatic damage detection from vehicle photos
  • ⚡ Fast Processing: Results in 3-5 seconds per image pair
  • 📊 Confidence Scoring: Detailed damage assessment with probability scores
  • 🎨 Smart Visualization: Automatic damage highlighting and annotation
  • 📱 Web Interface: User-friendly Streamlit application

🏗️ Architecture

The system uses a multi-stage approach:

  1. Image Alignment: SIFT keypoint matching for perspective correction
  2. Change Detection: SSIM structural similarity analysis
  3. Segmentation: SAM (Segment Anything Model) for region identification
  4. Classification: CNN filtering to distinguish damage from non-damage
  5. Assessment: Overall severity and confidence scoring

🚀 Quick Start

Prerequisites

  • Python 3.8 or higher
  • CUDA-capable GPU (optional, for faster processing)

Installation

  1. Clone the repository

    git clone <repository-url>
    cd car-damage-detector
  2. Create virtual environment

    python -m venv venv
    
    # On Windows
    venv\Scripts\activate
    
    # On macOS/Linux
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Download SAM model (optional)

    # Download SAM checkpoint for enhanced segmentation
    wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth
    # Place in project root or specify path in configuration

Running the Application

  1. Start the web interface

    streamlit run app.py
  2. Open your browser and navigate to http://localhost:8501

  3. Upload photos:

    • Before photos: Car in good condition
    • After photos: Car after use/rental
  4. Click "Start Advanced Damage Detection" to analyze

📖 Usage Guide

Basic Workflow

  1. Navigate to "Damage Detection" page
  2. Upload before photos (car in good condition)
  3. Upload after photos (car after use/rental)
  4. Start analysis with the detection button
  5. Review results with damage highlighting and confidence scores

Best Practices

  • 📸 Photo Quality: Use high-resolution images (1920x1080 or higher)
  • ☀️ Lighting: Ensure consistent lighting conditions
  • 🚗 Framing: Include the entire vehicle in the frame
  • 📐 Angles: Take photos from similar angles when possible
  • 🕐 Timing: Capture photos at similar times of day

Configuration Options

The system allows fine-tuning of detection parameters:

# Adjust detection sensitivity
detector.set_damage_region_padding(0.4, 100)  # CNN context padding
detector.set_visualization_padding(0.5, 60)   # Visual marking padding

# Modify thresholds
detector.ssim_threshold = 0.75        # Change detection sensitivity
detector.confidence_threshold = 0.579 # CNN confidence threshold

🧠 Model Training

Training Your Own CNN Classifier

  1. Prepare training data in the training_data/ directory:

    training_data/
    ├── damage/
    │   ├── image1.jpg
    │   ├── image2.jpg
    │   └── ...
    └── no_damage/
        ├── image1.jpg
        ├── image2.jpg
        └── ...
    
  2. Run training script

    python train_damage_classifier.py
  3. Monitor training with real-time metrics and early stopping

  4. Model saved to models/best_damage_classifier.pth

Training Parameters

  • Architecture: ResNet18 with custom classification head
  • Input Size: 256x256 pixels
  • Augmentation: Random flips, brightness, contrast adjustments
  • Optimization: Adam optimizer with learning rate scheduling
  • Early Stopping: Training stops at 90% accuracy or max epochs

🛠️ Technical Details

Core Dependencies

  • PyTorch 2.0+: Deep learning framework
  • OpenCV: Computer vision operations
  • SAM: Segment Anything Model for segmentation
  • scikit-image: Image processing algorithms
  • Streamlit: Web interface framework

File Structure

car-damage-detector/
├── app.py                      # Main Streamlit application
├── damage_detector.py          # Core AI detection engine
├── damage_visualizer.py        # Damage visualization utilities
├── train_damage_classifier.py  # CNN training script
├── damage_dataset.py           # Dataset handling
├── requirements.txt            # Python dependencies
├── models/                     # Trained models directory
├── training_data/              # Training dataset
└── README.md                   # This file

About

AI-Powered Car Damage Detection System

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages