Skip to content

Repository files navigation

Smart Parking Management System

Real-time parking occupancy detection using YOLOv8, Kafka, MongoDB, and Flask


Overview

A real-time smart parking platform that combines computer vision and event-driven data engineering to monitor parking space availability. The system uses a YOLOv8-based object detection pipeline to analyze camera images, streams occupancy events through Apache Kafka, stores them in MongoDB, and serves live availability data via a Flask web dashboard that auto-refreshes every 5 seconds.


Architecture

Camera Images
     │
     ▼
[YOLOv8 Model] ──── occupancy detection
     │
     ▼
[Kafka Producer] ──── streams events to topics
     │
     ├──── IoT sensor topic ──► [Consumer] ──► MongoDB (parking_data)
     │
     └──── Image topic      ──► [Consumer] ──► MongoDB (image_stats)
                                                    │
                                                    ▼
                                            [Flask Dashboard]
                                         (auto-refresh every 5s)

Features

  • YOLOv8 computer vision — detects occupied/free parking spaces from images using a fine-tuned YOLO model (best.pt)
  • Apache Kafka streaming — event-driven architecture with separate producer/consumer pairs for IoT sensor data and image analysis
  • MongoDB storage — persists occupancy events with timestamps for both sensor and vision pipelines
  • Flask web dashboard — displays real-time available spaces from both data sources, with automatic 5-second refresh
  • Docker Compose — full containerized deployment of Kafka and MongoDB

Tech Stack

Component Technology
Object Detection YOLOv8 (Ultralytics), ONNX
Message Streaming Apache Kafka
Database MongoDB
Web Framework Flask
Containerization Docker Compose
Language Python 3.7+

Project Structure

car_parking/
├── app.py                # Flask web server and dashboard
├── producer.py           # Kafka producer for IoT sensor data
├── producer_images.py    # Kafka producer for camera images
├── consumer.py           # Kafka consumer → MongoDB (parking_data)
├── consumer_image.py     # Kafka consumer → MongoDB (image_stats)
├── image_to_data.py      # Image preprocessing pipeline
├── kafka_to_mongo.py     # Kafka–MongoDB bridge utilities
├── ml_model.py           # YOLOv8 inference wrapper
├── test.py               # Testing utilities
├── best.pt               # YOLOv8 fine-tuned model weights
├── best.onnx             # ONNX export of the model
├── docker-compose.yml    # Kafka + MongoDB containers
├── Templates/            # Flask HTML templates
└── images/               # Sample parking lot images

How to Run

Prerequisites

  • Python 3.7+
  • Docker and Docker Compose

1. Clone the repository

git clone https://github.com/karanehzm/car_parking.git
cd car_parking

2. Install Python dependencies

pip install flask pymongo kafka-python ultralytics opencv-python

3. Start Kafka and MongoDB containers

docker-compose up --build -d

4. Run the pipeline (in separate terminals)

# Start IoT data producer
python3 producer.py

# Start image producer
python3 producer_images.py

# Start IoT data consumer
python3 consumer.py

# Start image consumer
python3 consumer_image.py

# Start Flask web server
python3 app.py

5. Open the dashboard

Navigate to http://localhost:5000


Dashboard Preview

Smart Parking Dashboard


Author

Karaneh Zolfaghari Moghaddam
github.com/karanehzm

About

Real-time smart parking system using YOLOv8, Kafka, MongoDB and Flask

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages