Inspiration

Every year, thousands of accidents happen because drivers get tired and start to lose focus or even fall asleep—often without realizing it. We were inspired by a desire to make roads safer, so we wanted to create a low-cost solution that could warn people before something bad happens. Even regular laptops or PCs, with just a webcam, could help prevent serious incidents using live video analytics.

What it does

Our project is a real-time drowsiness detection system that uses your webcam to check two main things:

Eye closure (using Eye Aspect Ratio, EAR): Detects if your eyes remain closed for dangerously long intervals.

Yawning (using a custom-trained CNN model): Spotting repeated or long yawns as a sign of tiredness. If either is detected, the system plays a loud alarm to bring your attention back to the road.

How we built it

Used Python with OpenCV and MediaPipe to process live video frames and track facial landmarks.

Collected and cropped mouth images (open and closed) to create our own dataset, since pre-trained models didn’t work well for our faces/camera.

Trained a simple Convolutional Neural Network (CNN) in Google Colab to classify mouth state accurately on our data.

Converted the model to TensorFlow Lite (TFLite) for lightweight, offline inference.

Combined EAR and yawn detection logic in a single pipeline script, triggering an alert sound using SimpleAudio whenever a risk pattern is seen.

Challenges we ran into

Pre-trained mouth/yawn detection models from the internet didn’t generalize; they didn’t work on our images. The only fix was building and labeling our own dataset!

Getting good mouth crops: We had to carefully crop and save images, even from stock photos.

Tuning model thresholds: We used live console and visual output to find “just right” thresholds for ear and yawn detection.

Consistent lighting and camera quality: Training and testing needed to be similar (backgrounds, lighting, position) for strong model results.

Accomplishments that we're proud of

End-to-end, fully offline system: No cloud needed after setup—everything runs on a normal laptop.

Personalized, robust yawn detector: Our own model outperformed generic models by a huge margin.

The alarm reacts instantly to risky signs.

Very easy to demo or adapt for anyone—just by capturing new training images.

What we learned

Face/landmark tracking, image cropping, and real-world data collection basics.

How to make a neural network that actually works on your own webcam, not just on datasets.

“Failing fast” helps: public models not working wasn’t the end—a quick dataset and training session in Google Colab solved everything.

The importance of tuning, visualization, and iterating as you build real products.

Making a solution that can work anywhere if you update the training images.

What's next for Driver Drowsiness and Yawn Detection System

Testing in real vehicles: Move beyond laptop demos and integrate with mobile devices or Raspberry Pi.

Better generalization: Build a larger, more diverse mouth dataset, possibly using crowdsourcing.

Additional features: Add distraction detection (looking away, talking on phone, etc.).

User interface improvements: Provide visible dashboard, adjustable sensitivity, configurable alarm sounds.

Share our solution: Open sourcing our code and mouth training script so anyone can protect themselves with a custom detector.

Built With

  • alarm
  • colab
  • conversion)
  • google
  • model
  • playback)
  • quick
  • simpleaudio
  • tflite
  • training
  • with-python-3.11-opencv-(video-capture-&-image-processing)-mediapipe-(face/landmark-detection)-tensorflow-/-keras-(cnn-training
Share this project:

Updates