This project is aimed at detecting and identifying traffic rule violations by two-wheeler riders, with a focus on the detection of violations. The project utilizes three Models trained on Roboflow Cloud [1][2][3] to detect objects of interest in video frames. It saves the images of two wheelers which violated the traffic rules, along with image of their license plates.
Do check out my blog on entire working of this project.
The datasets used for this project are Helmet Detection Project, Face Detection, and Two Wheeler Lane Detection.
The Two Wheeler Lane Detection Dataset is created by Pratham Jaiswal (me), Arnav Rawat, and Shubham Sharma.
- Helmet Detection Project: Two-wheeler/motorcyclist, Helmet, License Plate
- Face Detection: Human Face
- Two Wheeler Lane Detection: Front-facing motorcycle, Rear-facing motorcycle
- Wrong Lane: Driving away from the camera.
- No Helmet: Any rider not wearing a helmet.
- Triple riding: More than two riders.
- Motorcycle Detection:
- Detects all two-wheelers/motorcycles in a frame.
- Bounding Box Extraction:
- For each detected motorcycle, extracts its bounding box.
- Orientation Check:
- Determines if the motorcycle is front-facing or rear-facing.
- Flags a "Wrong Lane Violation" if the motorcycle is rear-facing.
- Face and Helmet Detection:
- Detects faces and helmets within the cropped image.
- Counts the number of faces.
- Reduces the face count if the detected face and helmet areas overlap by more than 60%.
- No Helmet Violation:
- Detects helmets again and counts them.
- Flags a "No Helmet Violation" if no helmets are detected or if the number of faces is greater than 1.
- Triple Riding Violation:
- Sums up the final counts of helmets and faces.
- Flags a "Triple Riding Violation" if the sum is greater than 2.
- License Plate Detection:
- If any violation is detected, captures the license plate using the OCR.Space API.
- Saving Violation Data:
- Saves the violated motorcycle image along with its license plate image and text.
- Records the list of violations for each image.
- Clone this repository,
git clone https://github.com/pratham-jaiswal/two-wheeler-traffic-rule-violation.git
- Get your OCR.Space API key from here.
- Get your Roboflow API key by following this guide.
- Create a .env file with the following environment variables
OCR_SPACE_API=YOUR_OCRSPACE_API_KEY ROBOFLOW_API_KEY=YOUR_ROBOFLOW_API_KEY
- Put the video in your directory, which contains main.py, with the name input.mp4.
- Install the required libraries.
pip install -r requirements.txt
- Run the main.py.
This project is provided under the MIT License.