Skip to content

Add real-time webcam inference loop with FPS and compliance counters - #6

Open
MathewTech254 wants to merge 1 commit into
AIMLCLUBOCT:mainfrom
MathewTech254:feat/webcam-inference-loop
Open

MathewTech254 wants to merge 1 commit into
AIMLCLUBOCT:mainfrom
MathewTech254:feat/webcam-inference-loop

Conversation

@MathewTech254

Copy link
Copy Markdown

What this does

Turns the detect.py stub into an actual working detector. It pulls frames from your webcam (or a video file), runs them through YOLO, draws the boxes, and puts an FPS counter and a helmet/no-helmet tally in the corner.

pip install -r requirements.txt
python detect.py                                       # webcam
python detect.py --model helmet-yolov8n.pt --conf 0.5   # custom weights
python detect.py --source campus-footage.mp4           # video file

Press q to quit.

Closes #2

Things I ran into

The default yolov8n.pt is a COCO model and doesn't have a helmet class, so out of the box it will always say NO DETECTIONS no matter what you point it at. That's expected — you need weights trained on helmet classes, which you pass with --model. I mentioned it in the --help text so nobody thinks it's broken.

Class names came back in more shapes than I expected, so classify_label normalises them first. Helmet, no-helmet, No_Helmet, helmetless and without helmet all end up in the right bucket. A plain "no" in label check would have worked too, but it also matches things like Nose helmet, which is not a thing, but you get the idea. Also worth knowing: Ultralytics gives you names as a dict on most models and a list on others, so both are handled.

One more: the first version stopped the whole loop the first time a frame failed to read. Webcams drop frames, so now it puts up with 10 in a row before deciding the stream is actually over.

Testing

No webcam here, so I ran the loop against generated video and real photos with the GUI calls stubbed out.

  • python -m py_compile detect.py clean, --help shows all three flags, yolov8n.pt loads
  • 40-frame video end to end: every frame processed, correct window title, valid BGR frames, HUD drawn, q quits early, end of stream exits clean
  • Bad video path returns exit 1 without drawing anything
  • Real detections come through with boxes, labels and confidence
  • Fed it helmet-classed boxes to check the counters and the COMPLIANT / VIOLATION banner actually flip

Note

Only detect.py changed. requirements.txt and README.md untouched.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

🎉 Thank you for your Pull Request, @MathewTech254!

Welcome to AIML Club OCT! 🚀

A maintainer will review your code shortly. In the meantime:

Happy coding! 💻✨

@UmeshCode1

Copy link
Copy Markdown
Member

Hi @MathewTech254! 👋

Thank you so much for this PR! The real-time webcam loop, FPS calculation, normalized multi-label handling (\helmetless, \No_Helmet, etc.), and 10-frame drop tolerance are fantastic additions to make the detector actually deployable in live environments.

There is currently a small git conflict with the latest \main\ branch in \�eginner/safety-helmet-detector/detect.py\ (due to recent fallback updates).

Could you please sync your fork with upstream \main\ and rebase / resolve the conflict?
\\�ash
git fetch origin main
git rebase origin/main

resolve conflicts in detect.py, then:

git push --force-with-lease
\\

As soon as that's rebased, we are ready to approve and merge this! Appreciate your awesome work! 🚀

@MathewTech254

MathewTech254 commented Oct 23, 2026 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add real-time webcam inference loop to safety-helmet-detector

2 participants