Skip to content

Latest commit

 

History

History
217 lines (169 loc) · 10.2 KB

File metadata and controls

217 lines (169 loc) · 10.2 KB

Vehicle Image Comparison System - Project Overview

Project Purpose

This system is designed to detect license plate fraud by comparing vehicle images to determine if the same license plate appears on different vehicles. The primary use case is identifying when a license plate has been moved from one vehicle to another, which traditional OCR-based approaches cannot detect since the plate content remains identical.

Core Technology

  • Language: Go
  • Computer Vision: OpenCV (via gocv bindings)
  • Architecture: Modular package structure with clear separation of concerns
  • Deployment: Command-line tool supporting file paths and base64 image input

Key Innovation: IR Signature Analysis

The system's breakthrough feature analyzes the infrared reflectivity patterns around license plates rather than the plate content itself. Each vehicle model has unique IR signatures from:

  • Bumper materials (metal vs. plastic vs. rubber)
  • Mounting hardware and trim patterns
  • Surface textures and 3D geometry
  • IR illumination gradients and shadow patterns

This enables detection of the same plate on different vehicles by comparing the surrounding "fingerprint."

System Architecture

1. Image Preprocessing (internal/preprocessor/)

Quality Assessment (quality.go)

  • Blur detection: Laplacian variance analysis
  • Contrast evaluation: Standard deviation of pixel intensities
  • Noise assessment: High-frequency content analysis
  • Overall quality scoring: Composite metric for image usability
  • Minimum quality threshold: Rejects images below 0.3 quality score

View & Lighting Classification (classifier.go)

  • Vehicle view detection: Front vs. rear identification using structural cues
  • Lighting condition analysis: Daylight vs. infrared classification
  • Confidence scoring: Ensures reliable classification before comparison
  • Consistency validation: Verifies both images have matching view/lighting

2. Feature Extraction (internal/extractor/)

Geometric Features (geometric.go)

  • Vehicle proportions: Width/height ratios, upper/lower section ratios
  • Structural elements: Detection and classification of vehicle components
  • Reference points: Key landmarks for alignment and comparison
  • License plate area: Geometric relationship analysis
  • Universal compatibility: Works regardless of lighting conditions

Light Pattern Analysis (lights.go)

  • Light element detection: Headlights, taillights, DRL, fog lights
  • Pattern signatures: Mathematical representations of light configurations
  • Spatial relationships: Positioning, spacing, and symmetry analysis
  • Intensity profiling: Brightness and shape characteristics
  • Configuration analysis: Number of elements and arrangement patterns

License Plate Detection (plate.go)

  • Retroreflective detection: Identifies bright plate regions in IR images
  • Geometric validation: Aspect ratio and size constraints for US plates
  • Confidence scoring: Multi-factor assessment of plate candidates
  • Fallback mechanisms: Robust detection even in challenging conditions
  • Position optimization: Searches likely plate locations when detection fails

IR Signature Extraction (ir_signature.go)

  • Surrounding region analysis: 1.5x plate area for comprehensive context
  • Reflectivity mapping: 8x8 grid showing material response patterns
  • Material classification: 6-component signature distinguishing surface types
  • Shadow pattern detection: 3D structure indicators from IR illumination
  • Illumination gradients: Directional brightness analysis from IR source
  • Texture characterization: Surface roughness and pattern features

3. Comparison Engine (internal/comparator/)

Adaptive Weighting System

Daylight Images:

  • Geometric features: 30%
  • Light patterns: 30%
  • Bumper features: 20%
  • Color analysis: 20%

Infrared Images:

  • Geometric features: 35%
  • Light patterns: 35%
  • Bumper features: 20%
  • IR signatures: 10%

IR Signature Comparison

  • Reflectivity map matching: Pixel-by-pixel comparison of material response (35% weight)
  • Material signature correlation: Vector comparison of surface properties (30% weight)
  • Shadow pattern alignment: Spatial matching of 3D structure indicators (15% weight)
  • Illumination/texture analysis: Gradient and surface feature comparison (20% weight)

Robustness Features

  • NaN/Infinity protection: Comprehensive validation preventing JSON marshaling errors
  • Division-by-zero safeguards: Robust ratio calculations with fallback values
  • Confidence assessment: Multi-factor reliability scoring
  • Similarity thresholds: Adaptive decision boundaries based on lighting conditions

4. Data Models (internal/models/)

Core Structures (types.go)

  • VehicleImage: Image container with metadata and quality metrics
  • LicensePlateRegion: Detected plate bounds with confidence scoring
  • IRSignature: Comprehensive IR analysis results
  • Processing metadata: Normalization and transformation records

Feature Definitions (features.go)

  • Geometric features: Proportions, structural elements, reference points
  • Light patterns: Element definitions, configurations, signatures
  • Material features: Color profiles, texture signatures, surface properties
  • Lighting-specific features: Daylight vs. infrared optimized analysis

Results (results.go)

  • Comparison outcomes: Boolean same-vehicle determination
  • Detailed scoring: Component-by-component similarity breakdown
  • Confidence levels: High/Medium/Low reliability assessment
  • Processing information: Timing, quality metrics, consistency flags
  • Validation methods: NaN/Infinity sanitization for robust output

5. Service Layer (pkg/vehiclecompare/)

Main Service (service.go)

  • Unified interface: Single entry point for all comparison operations
  • Input flexibility: File paths or base64 encoded images
  • Processing pipeline: Orchestrates preprocessing, extraction, and comparison
  • Error handling: Comprehensive validation and fallback mechanisms
  • Performance monitoring: Processing time measurement and optimization

Command Line Interface (cmd/main.go)

Usage Modes

# File-based comparison
./vehicle-compare -image1 path1.jpg -image2 path2.jpg [-output results.json] [-verbose]

# Base64 string comparison  
./vehicle-compare -image1-base64 <base64> -image2-base64 <base64> [-output results.json] [-verbose]

Output Features

  • Console summary: Key results with similarity percentage
  • Detailed scoring: Component breakdown in verbose mode
  • JSON export: Machine-readable results for integration
  • Processing metrics: Quality scores, timing, and consistency flags

Performance Characteristics

Accuracy Metrics

  • Identical image similarity: 86% (tested baseline)
  • Same vehicle threshold: 75% for daylight, 70% for infrared
  • False positive protection: IR signature analysis prevents plate-swapping false matches
  • Robust classification: Multi-factor confidence scoring

Processing Performance

  • Typical processing time: 300-400ms per comparison
  • Memory efficiency: Proper resource cleanup with defer statements
  • Scalability: Stateless design supports concurrent processing
  • Error resilience: Graceful degradation with fallback mechanisms

Fraud Detection Capabilities

License Plate Swapping Detection

  1. Same plate, different vehicles: IR signature differences reveal vehicle model changes
  2. Retroreflective analysis: Plate brightness patterns indicate mounting variations
  3. Surrounding context: Material and geometric differences expose fraud attempts
  4. 3D structure analysis: Shadow patterns reveal bumper and trim differences

Validation Scenarios

  • Legitimate matches: Same vehicle photographed at different times/angles
  • Fraud detection: Identical plate on different vehicle models
  • Environmental variations: Robust performance across lighting and weather conditions
  • Image quality tolerance: Functional with moderate blur, noise, and exposure variations

Technical Robustness

Error Handling

  • Input validation: Comprehensive checks for image format, size, and quality
  • API compatibility: Defensive programming against OpenCV version changes
  • Numerical stability: NaN/Infinity protection throughout calculation pipeline
  • Resource management: Proper cleanup preventing memory leaks

Extensibility

  • Modular architecture: Easy addition of new feature extractors
  • Configurable weights: Adaptive scoring based on image characteristics
  • Plugin interface: Clean separation enabling algorithm improvements
  • Testing framework: Comprehensive validation supporting development

Future Enhancement Opportunities

Advanced Features

  • Multiple view support: Side and angled vehicle perspectives
  • Temporal analysis: Sequential image comparison for tracking
  • Database integration: Large-scale plate fraud detection systems
  • Real-time processing: Video stream analysis capabilities

Algorithm Improvements

  • Machine learning integration: Trained models for enhanced accuracy
  • Advanced IR analysis: Thermal imaging support beyond near-infrared
  • Enhanced plate detection: Deep learning-based region proposals
  • Improved material classification: Spectral analysis techniques

Deployment Considerations

Requirements

  • Go 1.21+: Modern language features and performance
  • OpenCV 4.x: Computer vision processing capabilities
  • System memory: Sufficient RAM for image processing operations
  • Processing power: CPU adequate for real-time analysis needs

Security

  • Input sanitization: Protection against malicious image files
  • Resource limits: Prevention of denial-of-service through large images
  • Data privacy: No persistent storage of processed images
  • Audit logging: Processing metrics for forensic analysis

This system represents a significant advancement in automated license plate fraud detection, providing law enforcement and security organizations with a powerful tool for identifying vehicle-related crimes through advanced computer vision analysis.