AI Helmet Violation and Number Plate Detection System with Django
Back to ProjectThis takes about 20 to 30 minutes the first time, mostly because of downloads. After that it starts in seconds. Go step by step and don't skip the helmet model part.
Open the project folder and create a virtual environment. Open a terminal inside the helmet_anpr folder and run:
python -m venv venv
venv\Scripts\activate
On Linux or macOS, use source venv/bin/activate instead. You'll see (venv) at the start of the line once it's active.
Install the dependencies.
pip install -r requirements.txt
This pulls in Django, Ultralytics, fast-alpr, OpenCV, ReportLab, OpenPyXL and imageio-ffmpeg. It can take a few minutes, so let it finish.
Add the helmet model. This step is required. Download a pre-trained YOLOv8 helmet detection .pt file. Search "helmet detection yolov8" on Roboflow Universe (universe.roboflow.com) or on Hugging Face. Rename it and place it here:
ml_models/helmet_best.pt
Match the class order. Look at the model card or its data.yaml to see which number means helmet. Then open config/settings.py and update:
"HELMET_CLASS_NAMES": {
0: "helmet",
1: "no_helmet",
},
If your model has them the other way round, swap them. This one detail decides whether the project works correctly.
Set up the database and the admin login.
python manage.py migrate
python manage.py create_demo_admin
That creates the user admin with password admin123. If you'd rather choose your own, run python manage.py createsuperuser.
Start the server.
python manage.py runserver
Open http://127.0.0.1:8000/ in your browser and log in.
http://192.168.1.5:8080./video at the end, for example http://192.168.1.5:8080/video. Then click Start.ml_models/helmet_best.pt, or the name is slightly off (watch for helmet_best.pt.pt on Windows with hidden extensions). The app still runs, but helmet status shows as unknown until you fix it.HELMET_CLASS_NAMES./video.FRAME_SKIP or lower RESIZE_WIDTH in DETECTION_CONFIG.python scripts/test_pipeline.py path\to\traffic_video.mp4 --output scripts\test_output.avi
Violations should print in the terminal, and an annotated video should be saved.If all four of those work, you're ready for your demo.
Our team is here to assist you with installation and setup.