This project uses the power of computer vision to detect when a vehicle breaks a certain traffic rule and scrapes its license plate to store it in the database.
- It can detect vehicles (car, auto, bike/2 wheelers).
- It can detect if a person is wearing a helmet of not.
- It can scrape the license plate from vehicles which break traffic rules.
- save the license plate numbers and related information in the database.
- To implement computer vision ideas in the field of law inforcements.
- To automate law inforcement.
- To demonstrate implementation of data science in real life.
- Algorithmic knowledge (YOLOV5)
- Data collection (from online and offline videos, images)
- Data preparation (labeling images)
- Model training and testing
- Logic building
- Python Programming (backend)
- Web Development (flask)
- Cassandra Database (setup and usage)
- Version control (git, github)
- Online dataset:
- https://www.kaggle.com/datasets/andrewmvd/helmet-detection
- google images for helmet
- Offline:
- videos of vehicles were captured by me near traffic signals and junctions
- i manually picked images from the videos
- labeled the images for training
- images of vehicles (autos, 2 wheelers, cars)
- helmet images
- about 250 and 200 images where used to train the vehicle and helmet detection models respectively.
- 100 extra images were used for testing the models.
- Labelimg
- easyocr
Requirements
- Python 3.8
- YoloV5
- Cassandra 3.11
- Windows or ubuntu 20.04 (preferbly, setup Cassandra on dockers if working on windows)
- First clone the yolov5 repository in the folder you want to set it up and install the requirements
git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
-
Then download this repository and have all these contents in the yolov5 folder
- Take the vehicle.pt, helmet.pt, detect2.py and detect3.py files out of their respective
-
Install the dependencies using the requirements file provided in this repository:
pip install -r requirements.txt # install
- The vehicle.pt and helmet.pt are the trained weights which are used for detection
- The detect2.py is my own and basically it does the same as detect.py but does not create bounding boxes and instead returns those values
- The detect3.py is what is actually used by the application for detecting vehicles, helmets and scraping license plates
- The detect.py file which comes with yolov5 is used to detect and output images/videos.
python detect.py --source <image/video location> --weights <vehicle.pt or helmet.pt>
- Does any vehicle break the traffic light (signal breaker)?
- First it needs a bounding box so that it can detect objects within it
- The reason for this is that a traffic camera covers pedestrians and vehicles from other lanes so its best to create a bounding box.
- And it also reduces unnessary load on the processor.
- Then it needs to know where the zebra crossing is
- You can create a model for it. I collected the data but haven't labelled and trained the model for it.
- It needs the know the signal from the traffic signal.
- This is currently set to red and for zebra crossing i have kept the its as 200 pixels from the bottom.
- So if a vehicle tries to leave the frame from the bottom of the frame then it is considered as signal breaker
- OCR: easyocr is used in this project to detect the license plate and read it.
- Every time a 2 wheeler is detected it the helmet is checked.
- The first challenge i faced was understanding how yolov5 works because after some time of playing around with it i realized that i can't just use it as it is and had to make my own version of the detect.py for the project.wen
- Then the second challenge was the data collection and preparation as the online data sources can't be used as it is (The above give kaggle dataset has a lot of images with bicycle and construction hats and it does not represent the kind of images it will encounter in real life) and there was less data to build both a helmet detection and vehicle detection model (indian vehicles, autos, 2 wheelers)
- I went out and recorded a few videos of vehicles on roads where there is dense traffic and also shown a few of those videos here for demo.
- After collection i labelled the images using labelimg
- Then there where a few problems i faced in cassandra installation and setup but i quickely learnt how to deal with them after a lot of stackoverflow, datastax and github searches.
- I also had some issues with opencv and where basically i found out that some packages where not of the right versions needed and caused a issue with imread and other functions. (solution was to delete and recreate the virtual environment)
- YoloV5
- Usage of cassandra DB
- Usage of git, github.
- opencv
- logic building
- model building and testing
For support, email [email protected] or contact me on linkedin.
- You can use this project for further developing it and adding your work in it. If you use this project, kindly mention the original source of the project and mention the link of this repo in your report.
- You can add more traffic rule detection using new ideas.
- I am a data science enthusiast.
- Currently studying 4th year in CSE
- I have some helpful content on kaggle as well so, check it out if interested