How xennonite/ai-smart-parking works
Purpose and Entry Points
This repository implements a camera-based smart-parking prototype: detect vehicles from periodic ESP32-CAM images, map detections to configured parking polygons, and send occupancy state to an entrance ESP32. The production control-loop entry point is AI_Vision_System/master_system.py. Setup workflows are AI_Vision_System/setup_slots.py and AI_Vision_System/capture_high_res.py; embedded gate/display firmware is esp32.cpp.
Camera Data Acquisition
The vision server obtains high-resolution still images from the ESP32-CAM over HTTP rather than consuming a continuous stream. AI_Vision_System/capture_high_res.py supports collecting site-specific training images, while AI_Vision_System/master_system.py consumes camera images during runtime. The camera is an external ESP32-CAM running a camera web server and reachable on the local network.
Slot Configuration Boundary
Parking geometry is a site-specific configuration boundary. AI_Vision_System/setup_slots.py presents camera imagery for an operator to click each bay’s corners and persists those polygons in AI_Vision_System/parking_data.json. Runtime logic treats this JSON map as the authoritative inventory and avoids any physical sensor dependency per slot.
Vision Inference
The central Python process loads custom YOLOv8 vehicle-detection weights from AI_Vision_System/best.pt and runs inference on each fetched frame in AI_Vision_System/master_system.py. Model training is external to the runtime repository: images are annotated through Roboflow and trained with Ultralytics YOLOv8, typically using GPU-backed Google Colab.
Occupancy Resolution
AI_Vision_System/master_system.py converts vehicle bounding boxes into center pixels, then evaluates each center against each configured slot polygon using OpenCV point-in-polygon/ray-casting behavior. This translates model detections into an ordered binary slot-state array, such as occupied versus available, which is the core domain output.
Hardware Command Path
The Python server serializes and sends occupancy state through local-network HTTP requests to the entrance controller. esp32.cpp is the secondary ESP32 firmware boundary: it receives server updates and integrates physical I/O for the IR-triggered barrier servo and I2C LCD guidance display. The controller owns real-world actuation; Python owns camera interpretation and parking-state decisions.
Runtime and Deployment Shape
The prototype spans Python/OpenCV/Ultralytics on a central vision host and C++ firmware on two ESP32-class devices. JSON carries slot geometry and state-oriented payloads; HTTP REST and local Wi-Fi/mDNS provide device connectivity. The camera endpoint can be replaced by RTSP/CCTV sources, and the inference stage can move to a centralized GPU server processing multiple camera feeds.
Main entry points: master_system.py Master system · esp32.cpp Entrance controller firmware · setup_slots.py Slot setup · capture_high_res.py Training capture
Components 14
Vision host
Python control loop and site setup tools.
- Master system · Fetches frames, detects vehicles, resolves occupancy, and sends updates.
AI_Vision_System/master_system.py - Camera image fetch · Obtains periodic high-resolution still images.
AI_Vision_System/master_system.py - Vehicle inference · Runs custom vehicle detection on each frame.
AI_Vision_System/master_system.py - Occupancy resolution · Maps bounding-box centers to ordered binary slot states.
AI_Vision_System/master_system.py - Slot setup · Captures operator-selected parking-bay polygons.
AI_Vision_System/setup_slots.py - Training capture · Collects site-specific high-resolution images.
AI_Vision_System/capture_high_res.py - Parking polygons · Authoritative site parking inventory.
AI_Vision_System/parking_data.json - Custom YOLO weights · Vehicle-detection weights loaded by runtime.
AI_Vision_System/best.pt
ESP32 devices
Networked camera and entrance controller.
- ESP32-CAM · Serves still images over local-network HTTP.
- Entrance controller firmware · Receives occupancy updates and controls physical I/O.
esp32.cpp - Barrier servo · IR-triggered entrance barrier.
- Guidance LCD · Displays parking guidance.
External ML workflow
Model preparation occurs outside runtime.
- Roboflow annotation · Annotates collected training imagery.
- Ultralytics training · Trains YOLOv8 weights externally.
Connections 16
- ESP32-CAM → Camera image fetch: HTTP still images
- Camera image fetch → Master system: frames
- Master system → Vehicle inference: frame
- Custom YOLO weights → Vehicle inference: loads
- Vehicle inference → Occupancy resolution: vehicle boxes
- Parking polygons → Occupancy resolution: slot polygons
- Occupancy resolution → Master system: binary slot states
- Master system → Entrance controller firmware: HTTP occupancy update
- Entrance controller firmware → Barrier servo: servo control
- Entrance controller firmware → Guidance LCD: I2C guidance
- ESP32-CAM → Slot setup: camera imagery
- Slot setup → Parking polygons: persists polygons
- ESP32-CAM → Training capture: high-resolution images
- Training capture → Roboflow annotation: training images
- Roboflow annotation → Ultralytics training: annotated dataset
- Ultralytics training → Custom YOLO weights: trained weights