How kouz-1/moroccan_plates_detection works
Project Type and Purpose
• This is a standalone, end-to-end desktop application (Tkinter GUI) for Moroccan license-plate detection and recognition.
• It implements a sequential computer-vision/ML pipeline: input acquisition → plate detection (YOLOv5) → image preprocessing → character segmentation → character recognition (CNN) → result storage/display.
File Structure
Top-level files and folders:
• README.md, requirements.txt – project overview and dependencies
• gui.py, gui2.py – Tkinter GUI front ends
• char_model/char_model_1.h5 – trained CNN for character classification
• yolov5_model/best.pt – trained YOLOv5 model for plate detection
• process/ – core pipeline modules:
– main.py, main_char.py – orchestrators integrating all steps
– detect_char.py, segment_characters.py, find_contours.py – image-processing helpers
– predict_crop.py, save_plate_json.py, store_plate_to_mysql.py, check_plate_status.py, vehicle_manager.py – recognition, mapping to Latin, storage, and law-check
• cropped_plates/, json_plates/plates.json, predictions.txt – file-based I/O
• test_images/ – sample inputs
README for Technical Stack and Pipeline
• Python + OpenCV for image handling
• YOLOv5 (PyTorch) for object detection
• TensorFlow/Keras for CNN character recognition
• MySQL for status checks
• Tkinter for GUI
Main Components
A. User Interface Layer (GUI)
• Modules: gui.py / gui2.py (Tkinter)
• Functions: Load Image/Video/Camera, Start Detection, Check Status, Exit
B. Input Sources
• Static image files, video files, webcam stream
C. Plate Detection Service
• YOLOv5 Model (yolov5_model/best.pt) loaded by detect_plate module
• Output: cropped plate images → saved to cropped_plates/
D. Preprocessing and Segmentation
• Preprocessor (grayscale, resize, denoise)
• Contour-based segmentation (find_contours.py) → individual character crops
E. Character Recognition Service
• CNN model (char_model_1.h5) loaded by predict_crop.py
• Maps Arabic → Latin (via vehicle_manager.py/ JSON mapping)
• Produces plate string (e.g., “82227-A-6”)
F. Business Logic / Status Check
• store_plate_to_mysql.py: store detected plate in MySQL
• check_plate_status.py: query database to flag violations
G. Output and Storage
• JSON output (json_plates/plates.json)
• predictions.txt (flat-file log)
• GUI display of results and status
Relationships and Data Flow
• GUI triggers the Pipeline Orchestrator (main.py or main_char.py)
• Orchestrator calls Plate Detection → yields cropped images
• Cropped images feed into Preprocessing & Segmentation → character images
• Character images passed to CNN for recognition → returns character labels
• Recognized plate string sent to Vehicle Manager for mapping & status check
• Results flow back to GUI for display and to storage modules (JSON, MySQL, flat files)
Architectural Patterns and Principles
• Layered architecture: UI → Application Logic → ML Services → Persistence
• Single-process, modular design: each .py file encapsulates a distinct step
• Clear separation of concerns: detection, segmentation, recognition, storage
• Extensibility points: swap models (YOLOv5, char CNN), change storage back ends
d. To “Preprocessor” → “Segmenter” → “CNN Char Recognizer”