This project leverages deep learning techniques to create an intelligent system that can detect bikes, verify helmet usage, and locate number plates in video footage. This solution combines object detection and image classification models, leveraging YOLOv3 for bike and number plate detection, and a custom CNN for helmet classification.
The objective of this project is to provide an AI-driven solution that can detect bikes, verify helmet usage, and locate number plates from video footage in real-time. This application uses both pre-trained and custom-trained deep learning models to perform these tasks.
- Streamlit: A Python-based web framework used to build and display the real-time video analysis UI.
- Python 3.10: The core language used for developing the project.
- OpenCV: Used for video processing and real-time frame capture.
- YOLOv3 (You Only Look Once): A pre-trained object detection model used for detecting bikes and number plates.
- Model:
yolov3-custom.cfg,yolov3-custom_7000.weights
- Model:
- TensorFlow + Keras: Used for loading and utilizing the custom helmet detection model.
- Model:
helmet-nonhelmet_cnn.h5(CNN-based)
- Model:
- Imutils, NumPy, Pillow: Utilities for image and video frame processing.
Ensure you have Python 3.10 installed on your system. For managing dependencies, this project uses UV (a dependency management tool).
# If UV is not installed, run the following:
pip install uvcd helmet-projectUse UV or venv to create a virtual environment:
# Create a virtual environment using uv
uv venvActivate the virtual environment:
# For macOS/Linux
source env/bin/activate
# For Windows
env\Scripts\activateInstall the project dependencies listed in requirements.txt:
# Install dependencies using uv
uv add -r requirements.txtCopy the provided .env.example to .env:
cp example.env .envUpdate the .env file with the user details as needed:
USER1_EMAIL=demo@example.com
USER1_PASSWORD=password123
USER2_EMAIL=user2@example.com
USER2_PASSWORD=user2passwordYou can now run the application using the following command:
uv run streamlit run main.pyThis will start the app locally and open it in your browser. You should be able to login & upload a video and see the real-time helmet and number plate detection results.
Here’s a breakdown of the project files and their purpose:
.
├── README.md # Project description & setup instructions
├── example.env # Template for environment variables
├── helmet-nonhelmet_cnn.h5 # Custom CNN model for helmet classification
├── helmet_project_summary.md # Summary and explanation of the project
├── main.py # Main entry point for the Streamlit app
├── output.avi # Sample output video (for testing)
├── pyproject.toml # Project configuration file (for uv)
├── requirements.txt # Required Python dependencies
├── source.py # Detection logic (YOLOv3 and helmet detection)
├── temp # Temporary directory for storing uploaded files
├── uv.lock # uv dependency lock file
├── yolov3-custom.cfg # YOLOv3 configuration file
└── yolov3-custom_7000.weights # YOLOv3 trained weightsThe YOLOv3 model is used for detecting bikes and number plates in each frame of the uploaded video. The detection is performed using the YOLOv3 configuration and weights (yolov3-custom.cfg and yolov3-custom_7000.weights).
A custom CNN model (helmet-nonhelmet_cnn.h5) is used to classify whether a detected bike rider is wearing a helmet or not. The image of the rider’s head is cropped from the frame and passed to the CNN for classification.
- User Authentication: Login using demo credentials stored in a
.envfile. - Real-time Detection: Upload a video and detect bikes, helmets, and number plates in real-time.
- Customizable User Management: Add multiple users by modifying the
.envfile.