A computer vision app for real-time parking space monitoring. It uses YOLOv8 (Ultralytics) for object detection, polygon–object overlap for occupancy, optional uncertainty and “frequent hit” logic, and interactive tools to create, edit, and delete spaces.
- Universal or class-filtered detection — all COCO classes or a restricted list (e.g. vehicles only)
- Interactive polygons — click four corners per space; visual feedback while drawing
- Edit and delete modes — adjust or remove spaces without editing JSON by hand
- Uncertainty and timing — borderline overlap states and dwell time before “probably occupied”
- Frequent detections — treat noisy partial overlaps as occupied when hits spike in a window
- Free / occupied time stats — rolling totals shown on the overlay
- JSON configuration — thresholds and device selection in
config/settings.json - CPU / CUDA / auto — configurable inference device
Park_space_detector_Yolov8/
├── src/
│ └── parking_detector.py # Main application
├── config/
│ └── settings.json # Runtime settings
├── data/
│ └── parking_spaces.json # Saved parking polygons
├── models/
│ └── yolov8n.pt # YOLO weights (downloaded on first run)
├── docs/
│ └── README_Detailed.md # Detailed documentation
├── examples/
│ └── *.png # Sample images
├── scripts/
│ ├── install.sh # Setup helper
│ └── switch_device.sh # Toggle CPU/CUDA/auto in config
├── tests/
│ ├── conftest.py # Shared pytest fixtures
│ └── test_parking_detector.py # Unit tests
├── .github/workflows/ci.yml # CI (pytest on Ubuntu)
├── requirements.txt
├── requirements-dev.txt # pytest (local + CI)
├── pytest.ini
└── README.md
pip install -r requirements.txtcd src
python parking_detector.pyFrom the repository root you can also run: python src/parking_detector.py.
pip install -r requirements.txt -r requirements-dev.txt
pytest -vTests run on every push and pull request to main via GitHub Actions (see .github/workflows/ci.yml).
Edit video_path in src/parking_detector.py:
# Local file
video_path = '/path/to/your/video.mp4'
# Webcam
video_path = 0
# IP camera / MJPEG
video_path = 'http://your-camera-ip/stream'Auto (default):
{
"device": "auto",
"force_cpu": false
}Force CPU:
{
"device": "cpu",
"force_cpu": true
}Force CUDA:
{
"device": "cuda",
"force_cpu": false
}| Key | Action |
|---|---|
D |
Debug — click boxes to append their class IDs to tracked_objects |
E |
Edit — pick a space, then click four new corners |
R |
Delete — click a space to remove it |
U |
Toggle universal vs. cars-only (uses tracked_objects when off) |
S |
Save polygons to data/parking_spaces.json |
C |
Clear interaction modes and tracking caches |
Q |
Quit |
- Normal — click four corners per space; the polygon closes automatically after the fourth point.
- Edit (
E) — click inside a space to select it, then place four corners again. - Delete (
R) — click inside a space to delete it. - Debug (
D) — all detections drawn; click a box to track that class in debug-driven workflows.
{
"universal_detection": true,
"occupancy_threshold": 0.6,
"uncertainty_threshold": 0.3,
"uncertainty_time_threshold": 3.0,
"frequent_detection_threshold": 10,
"frequent_detection_window": 10.0,
"tracked_objects": [2, 67]
}| Field | Meaning |
|---|---|
universal_detection |
If true, use all detected classes; if false, only IDs in tracked_objects |
occupancy_threshold |
Min overlap ratio (0–1) for occupied |
uncertainty_threshold |
Lower bound for uncertain partial overlap |
uncertainty_time_threshold |
Seconds in uncertainty before probably occupied |
frequent_detection_threshold |
Hits needed inside the window for frequent state |
frequent_detection_window |
Sliding window (seconds) for frequent hits |
tracked_objects |
COCO class IDs when not in universal mode |
force_cpu |
Force CPU even if CUDA exists |
device |
"auto", "cuda", or "cpu" |
| State | Color (BGR-style intent) | Meaning |
|---|---|---|
| Free | Green | Below uncertainty threshold |
| Occupied | Red | Above occupancy threshold |
| Uncertain | Yellow | Partial overlap, still stabilizing |
| Probably occupied | Orange-red | Uncertain long enough |
| Frequent | Magenta | Many partial hits in a short window |
Minimum: Python 3.8+, 4 GB RAM, OpenCV-capable environment.
Recommended: Python 3.9+, 8 GB+ RAM, NVIDIA GPU with CUDA for real-time HD streams.
chmod +x scripts/install.sh
./scripts/install.shApache License 2.0 — see the LICENSE file.
v2.0 — Interactive editing, uncertainty / timing, and frequent-detection handling.
Tip: Stable lighting and a fixed camera angle improve overlap-based occupancy. Calibrate thresholds (occupancy_threshold, uncertainty_threshold) for your scene.
Repository description (short line for the GitHub About field):
Real-time parking occupancy monitor with YOLOv8, OpenCV, interactive polygons, uncertainty timing, and JSON configuration.
Suggested topics (add under repository Settings → General → Topics):
yolov8 ultralytics opencv pytorch computer-vision object-detection parking-detection real-time deep-learning python