An AI-powered system for automatic car damage detection using SAM + CNN + SSIM hybrid technology.
Example: Before and after comparison with AI-detected damage highlighting
- 🔍 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
The system uses a multi-stage approach:
- Image Alignment: SIFT keypoint matching for perspective correction
- Change Detection: SSIM structural similarity analysis
- Segmentation: SAM (Segment Anything Model) for region identification
- Classification: CNN filtering to distinguish damage from non-damage
- Assessment: Overall severity and confidence scoring
- Python 3.8 or higher
- CUDA-capable GPU (optional, for faster processing)
-
Clone the repository
git clone <repository-url> cd car-damage-detector
-
Create virtual environment
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
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
-
Start the web interface
streamlit run app.py
-
Open your browser and navigate to
http://localhost:8501 -
Upload photos:
- Before photos: Car in good condition
- After photos: Car after use/rental
-
Click "Start Advanced Damage Detection" to analyze
- Navigate to "Damage Detection" page
- Upload before photos (car in good condition)
- Upload after photos (car after use/rental)
- Start analysis with the detection button
- Review results with damage highlighting and confidence scores
- 📸 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
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-
Prepare training data in the
training_data/directory:training_data/ ├── damage/ │ ├── image1.jpg │ ├── image2.jpg │ └── ... └── no_damage/ ├── image1.jpg ├── image2.jpg └── ... -
Run training script
python train_damage_classifier.py
-
Monitor training with real-time metrics and early stopping
-
Model saved to
models/best_damage_classifier.pth
- 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
- 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
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
