This is a Python-based Smart Parking System designed to detect vehicles in a parking lot and determine the occupancy status of predefined parking slots. The system uses object detection to identify vehicles and maps them to polygon-shaped parking slots using geometric calculations.
- Real-time parking slot occupancy detection.
- Scalable to different resolutions and parking layouts.
- Flexible input options (video stream, webcam, or video file).
- Modular design with components for streaming, detection, and slot management.
.
├── Main.py # Main script to run the application
├── Stream.py # Handles video streaming
├── Slot.py # Manages parking slot definitions and occupancy checks
├── Model.py # Performs vehicle detection using a TensorFlow Lite model
├── slots.json # JSON file defining parking slots and the original resolution
├── Video_test/ # Directory for test video streams
├── efficientdet_lite0.tflite # Pretrained object detection model
└── README.md # Project documentation
-
Clone the repository:
git clone https://github.com/your-username/smart-parking-system.git cd smart-parking-system
-
Install dependencies:
- Python 3.8 or higher is required.
- Install required packages:
Example
pip install -r requirements.txt
requirements.txt
:opencv-python mediapipe numpy
-
Prepare the environment:
- Ensure you have a
slots.json
file defining parking slots (see the example below). - Place your test video streams or stream URLs in the appropriate location.
- Ensure you have a
-
Run the application:
python Main.py
-
Control:
- Press
q
to exit the application.
- Press
slots.json
: Theslots.json
file defines the parking slots and the original resolution of the layout. Example format:{ "original_resolution": [960, 540], "slots": { "1": [[432, 405], [401, 366], [467, 363], [514, 401]], "2": [[530, 410], [490, 370], [560, 370], [600, 410]] } }
- Adjust resolution:
Update the
res
parameter inStream
to change the video resolution:self.stream = Stream(name="ESP-CAM Stream", stream_url="./Video_test/stream.mp4", res=1)
-
Streaming: The
Stream
class opens the video source (e.g., file, webcam, or IP camera) and processes frames. -
Object Detection: The
Model
class uses TensorFlow Lite to detect vehicles in each frame and returns bounding boxes for detected objects. -
Slot Management: The
Slot
class:- Scales the defined parking slots to the current frame resolution.
- Checks if detected objects overlap with any slots. 6CD9
- Returns the IDs of occupied slots.
-
Visualization: The application draws bounding boxes around detected vehicles and highlights parking slots in real-time:
- Red: Occupied slots.
- Green: Available slots.
- Fork the repository.
- Create your feature branch:
git checkout -b feature/your-feature
- Commit your changes:
git commit -m "Add your feature"
- Push to the branch:
git push origin feature/your-feature
- Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
- TensorFlow Lite for the object detection model.
- OpenCV and MediaPipe for processing and visualization.
- Inspiration from smart parking systems and IoT solutions.
Let me know if you need further customizations!