This project focuses on real-time object detection and video streaming. We utilize a deep learning model to identify and classify objects within a video feed, sending results to Firebase. The data is then displayed using a Flask-based API, while the video stream is managed through WebSockets. The system is versatile, suitable for monitoring, alert systems, or security setups.
- Ensure Python 3.x is installed.
- Install the necessary libraries:
The
pip install -r requirements.txt
requirements.txt
file should include Flask, Firebase Admin SDK, Torch, OpenCV, WebSockets, and any other dependencies.
- Place your Firebase credentials JSON file in the appropriate location and update
detect.py
with the correct path:cred = credentials.Certificate("path/to/your/serviceAccountKey.json")
- This configuration enables saving detection results to Firebase.
Project_Root/
│
├── scripts/
│ ├── detect.py # Main detection and Firebase logging script
│ ├── get_img.py # Script for WebSocket video streaming
│ ├── main.py # Flask API server
│
├── static/
│ └── inference.jpg # Image to show detections
│
└── config/
└── serviceAccountKey.json # Firebase credentials
-
Start the Detection Script:
- Runs the model, logs results to Firebase, and saves detection images.
python detect.py --weights <model_weights.pt> --source <input_source>
-
Run the WebSocket Server:
- Open a new terminal and execute
get_img.py
to stream video frames.
python get_img.py
- Open a new terminal and execute
-
Launch the Flask Server:
- Start the API server with
main.py
to handle alerts and data.
python main.py
- Start the API server with
- WebSocket Stream: Connect your WebSocket client to the stream (default port is 5000) for live images.
- API Endpoints:
GET /data
: Retrieve the latest alerts.POST /alarm
: Access alarm data.
-
Real-Time Object Detection:
- Utilizes a custom model for object detection in live streams, sending updates to Firebase.
- Implements Non-Max Suppression to highlight the most relevant detections.
-
Live Streaming via WebSockets:
- Streams video frames in real-time to connected clients.
-
REST API with Flask:
- Manages alerts and status updates, enabling easy integration with other systems.
-
Cloud Storage with Firebase:
- Saves detection results for remote access and scalability.
This project provides an efficient setup for real-time monitoring and object detection. It is designed for seamless integration into other applications and can be scaled for diverse use cases, such as security or industrial monitoring. The combination of streaming and API features ensures flexibility and reliability for various scenarios.