|
1 | | -# plate |
| 1 | +# 🚗 Multi-Task Vehicle Monitoring System |
| 2 | + |
| 3 | +A real-time, Python-based toolkit for intelligent vehicle analytics: |
| 4 | +- Vehicle detection |
| 5 | +- Brand & model classification |
| 6 | +- Color recognition |
| 7 | +- Persian (Iranian) license-plate OCR + city lookup |
| 8 | +- Accident detection with audio alerts |
| 9 | + |
| 10 | +Built on YOLO11 & YOLO8 & ResNet18, OpenCV, and PyTorch. Ideal for smart surveillance, traffic analysis, parking management, and smart-city applications. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## 🦾 Key Features |
| 15 | + |
| 16 | +- **Vehicle Detection** |
| 17 | + • YOLO11 car detector |
| 18 | +- **Brand & Model Classification** |
| 19 | + • ResNet18 classifier trained on 27 Iranian makes/models |
| 20 | +- **Color Recognition** |
| 21 | + • ResNet18 classifier for 12 common car colors |
| 22 | + • Color-coded bounding boxes & labels |
| 23 | +- **License-Plate Recognition (ANPR)** |
| 24 | + • YOLO11 plate detector + character detector |
| 25 | + • Parses 8-character Persian/Iranian plates |
| 26 | + • Looks up city/region from plate data |
| 27 | +- **Accident Detection & Alert** |
| 28 | + • YOLO11 accident detector |
| 29 | + • Red bounding box + “Accident (0.XX)” label |
| 30 | + • Plays configurable beep (`beep.mp3`) at alert intervals |
| 31 | +- **Real-Time Image & Video Support** |
| 32 | + • Live FPS counter |
| 33 | + • Saves annotated images & video clips with timestamped filenames |
| 34 | +- **Modular & Configurable** |
| 35 | + • Centralized `PATHS`, `THRESHOLDS`, `IMG_SIZE`, etc. |
| 36 | + • Easily swap models or adjust thresholds |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## 🚩 Getting Started |
| 41 | + |
| 42 | +### Prerequisites |
| 43 | + |
| 44 | +- Python 3.8+ |
| 45 | +- (Optional) CUDA-enabled GPU for real-time performance |
| 46 | + |
| 47 | +### Install Dependencies |
| 48 | + |
| 49 | +```bash |
| 50 | +pip install torch torchvision ultralytics opencv-python pandas playsound pillow numpy |
| 51 | +``` |
| 52 | + |
| 53 | +> It’s recommended to use a virtual environment. |
| 54 | +
|
| 55 | +### Prepare Model Weights |
| 56 | + |
| 57 | + `weights/` directory has: |
| 58 | + |
| 59 | +``` |
| 60 | +weights/ |
| 61 | +├── car_det_model.pt |
| 62 | +├── plate_det_model.pt |
| 63 | +├── car_name_model.pth |
| 64 | +├── color_model.pt |
| 65 | +├── char_model.pt |
| 66 | +└── accident_model.pt |
| 67 | +``` |
| 68 | + |
| 69 | +### License-Plate City Data |
| 70 | + |
| 71 | + `Plates/city_plateinfo.txt` (UTF-8 CSV) format: |
| 72 | + |
| 73 | +``` |
| 74 | +letter,number,city |
| 75 | +a,11,Tehran |
| 76 | +b,12,Isfahan |
| 77 | +... |
| 78 | +``` |
| 79 | + |
| 80 | +### Sound Alert |
| 81 | + |
| 82 | +Place your beep file at `sound/beep.mp3`. |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +## ⚙ Configuration Overview |
| 87 | + |
| 88 | +All major settings live in `img & video detection.py`: |
| 89 | + |
| 90 | +```python |
| 91 | +PATHS = { |
| 92 | + "car_det_model": "weights/car_det_model.pt", |
| 93 | + "plate_det_model": "weights/plate_det_model.pt", |
| 94 | + "car_name_model": "weights/car_name_model.pth", |
| 95 | + "color_model": "weights/color_model.pt", |
| 96 | + "char_model": "weights/char_model.pt", |
| 97 | + "accident_model": "weights/accident_model.pt", |
| 98 | + "city_plateinfo": "Plates/city_plateinfo.txt", |
| 99 | + "alert_sound": "sound/beep.mp3", |
| 100 | + "source": "INPUT.JPG", # or "input.mp4" / camera index |
| 101 | + "output": "output", |
| 102 | +} |
| 103 | + |
| 104 | +IMG_SIZE = (220, 165) # ResNet image size |
| 105 | +THRESHOLDS = { |
| 106 | + "car_name": 0.65, |
| 107 | + "car_color": 0.70, |
| 108 | + "accident": 0.50 |
| 109 | +} |
| 110 | +FONT_SCALE = 0.5 |
| 111 | +THICKNESS = 1 |
| 112 | +ALERT_INTERVAL_SEC = 2 # Min seconds between beeps |
| 113 | +``` |
| 114 | + |
| 115 | +--- |
| 116 | + |
| 117 | +## 🚘 Usage |
| 118 | + |
| 119 | +### Process a Single Image |
| 120 | + |
| 121 | +```bash |
| 122 | +python img & video detection.py |
| 123 | +# Make sure PATHS["source"] points to .jpg/.png |
| 124 | +``` |
| 125 | + |
| 126 | +- Displays annotated image |
| 127 | +- Saves to `output/output_YYYYMMDDhhmmss.jpg` |
| 128 | + |
| 129 | +### Process Video or Live Stream |
| 130 | + |
| 131 | +```bash |
| 132 | +python img & video detection.py |
| 133 | +# Set PATHS["source"] = "input.mp4" or camera index (0, 1, …) |
| 134 | +``` |
| 135 | + |
| 136 | +- Opens a real-time window with FPS |
| 137 | +- Saves annotated video to `output/output_YYYYMMDDhhmmss.mp4` |
| 138 | +- Press **q** to quit |
| 139 | + |
| 140 | +--- |
| 141 | + |
| 142 | +## 📂 Directory Structure |
| 143 | + |
| 144 | +``` |
| 145 | +. |
| 146 | +├── main.py |
| 147 | +├── weights/ # Model checkpoint files (6 files) |
| 148 | +├── Plates/ |
| 149 | +│ └── city_plateinfo.txt |
| 150 | +├── sound/ |
| 151 | +│ └── beep.mp3 |
| 152 | +├── INPUT.JPG / input.mp4 # Example inputs |
| 153 | +├── output/ # Auto-created outputs |
| 154 | +└── README.md |
| 155 | +``` |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +## 💡 Output Samples |
| 160 | + |
| 161 | +Below are example outputs from the system. |
| 162 | + |
| 163 | +### Example video Output |
| 164 | + |
| 165 | +click >> [video output](output/output_20250730095049.mp4) |
| 166 | + |
| 167 | +- Vehicle detection in video |
| 168 | +- Vehicle brand and color recognition |
| 169 | +- License plate recognition |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +### Example output with overlapping vehicles |
| 174 | + |
| 175 | +|  |  | |
| 176 | +|:---:|:---:| |
| 177 | +| Vehicle detection in the presence of occlusion | Overlapping vehicles detection | |
| 178 | + |
| 179 | +--- |
| 180 | + |
| 181 | +### Example output for license plate reading |
| 182 | + |
| 183 | +|  |  | |
| 184 | +|:---:|:---:| |
| 185 | +| Accurate license plate recognition | License plate city identification (Iranian plate) | |
| 186 | + |
| 187 | +|  | | |
| 188 | +|:---:|:---:| |
| 189 | +| Another example of license plate reading | | |
| 190 | + |
| 191 | +--- |
| 192 | + |
| 193 | +### Example output for detection of traffic accidents |
| 194 | + |
| 195 | +|  | | |
| 196 | +|:---:|:---:| |
| 197 | +| Accident detection in real-time traffic footage | | |
| 198 | + |
| 199 | +--- |
| 200 | + |
| 201 | +## 📚 Datasets & Data Collection |
| 202 | + |
| 203 | +Our models were trained on a combination of: |
| 204 | + |
| 205 | +- **Custom Scraped Images** from Iranian automotive platforms: |
| 206 | + - Iran Khodro (ایران خودرو) |
| 207 | + - Saipa (سایپا) |
| 208 | + - Divar (دیوار) |
| 209 | + - Bama (باما) |
| 210 | + - Other online classifieds & dealer sites |
| 211 | +- **Public Roboflow Collections** |
| 212 | + - Car detection (various makes/models) |
| 213 | + - License-plate detection & OCR |
| 214 | + - Accident/incident examples |
| 215 | +- **Annotation & Augmentation** |
| 216 | + - YOLO-formatted bounding boxes & labels |
| 217 | + - Standardized color, model & plate classes |
| 218 | + - Augmentations: scaling, rotation, lighting, blur |
| 219 | + |
| 220 | +--- |
| 221 | + |
| 222 | +## 🤝 Contributing |
| 223 | + |
| 224 | +1. Fork the repository |
| 225 | +2. Create a feature branch (`git checkout -b feature/xyz`) |
| 226 | +3. Commit your changes (`git commit -m "Add new feature"`) |
| 227 | +4. Push to your fork (`git push origin feature/xyz`) |
| 228 | +5. Open a Pull Request |
| 229 | + |
| 230 | +--- |
| 231 | + |
| 232 | +## License |
| 233 | + |
| 234 | +Distributed under the MIT License. See [LICENSE](LICENSE) for details. |
| 235 | + |
| 236 | +--- |
| 237 | + |
| 238 | +## 🔖 Topics & Keywords |
| 239 | + |
| 240 | +`vehicle-detection` · `car-recognition` · `car-color-detection` · `license-plate-recognition` · `persian-plates` · `anpr` · `accident-detection` · `yolo11` · `pytorch` · `opencv` · `deep-learning` · `smart-city` · `traffic-analysis` · `multitask-learning` |
| 241 | + |
| 242 | +--- |
| 243 | + |
| 244 | +> Github.com/RezaGooner |
| 245 | +
|
0 commit comments