element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Vision Thing
  • Challenges & Projects
  • Project14
  • Vision Thing
  • More
  • Cancel
Vision Thing
Blog Driver State Monitor with OpenCV and BeagleBone AI
  • Blog
  • Forum
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Vision Thing requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: vlasov01
  • Date Created: 19 Nov 2019 12:51 AM Date Created
  • Views 883 views
  • Likes 14 likes
  • Comments 7 comments
  • bbai
  • visionthingch
  • driver safety
  • gpio
  • sleep
  • distraction
  • opencv
  • buzzer
  • python-opencv
  • ai project
  • dsm
  • dlib
  • dms
Related
Recommended

Driver State Monitor with OpenCV and BeagleBone AI

vlasov01
vlasov01
19 Nov 2019
image

Vision Thing

Enter Your Project for a chance to win an Oscilloscope Grand Prize Package for the Most Creative Vision Thing Project!

Back to The Project14 homepage image

Project14 Home
Monthly Themes
Monthly Theme Poll

 

Idea

This project is an attempt to build a in-car safety device, which monitors drivers' attention to the road and create alerts if the driver becomes sleepy or distracted.

The statistics are quite alarming in regard to drowsy driving. Here are some numbers from the US  https://www.cdc.gov/features/dsdrowsydriving/index.html

  • An estimated 1 in 25 adult drivers (aged 18 years or older) report having fallen asleep while driving in the previous 30 days.
  • The US National Highway Traffic Safety Administration estimates that drowsy driving was responsible for 72,000 crashes, 44,000 injuries, and 800 deaths in 2013. However, these numbers are underestimated and up to 6,000 fatal crashes each year may be caused by drowsy drivers.

Texting while driving is another significant source of accidents a well. Take a look at the following incident, when a tram conductor got distracted by a mobile phone:https://www.facebook.com/DIMITRISRAISA/videos/2766426710042975/

I think there is a lot of value to having a robust and accessible solution for this safety challenge.

Journey

Driver State Monitor (DSM) with BeagleBone AI is a project I'm working on explore the capabilities of OpenCV and BeagleBone AI (BBAI) to improve drivers' safety. It is based on work done by Adrian Rosebrock, which was published in his blog "Drowsiness detection with OpenCV" https://www.pyimagesearch.com/2017/05/08/drowsiness-detection-opencv/.

Theory

The best way not to fall asleep while driving is to have good regular sleep. You can read about it in one of my projects Saving Sleep with PocketBeagle .

I'm using HoG Face Detector implemented in Dlib library. It has its strong and weak points.

Pros

  1. Fastest method on CPU and works well on BBAI AM5729. No dependencies for accelerators like TI EVE or TI DSP cores.
  2. Light-weight model, fits well into BBAI.
  3. Work well for frontal and slightly non-frontal faces and under small occlusion.
  4. Adrian Rosebrock code provided a good accelerator and a starting base to extend.

Cons

  1. Doesn't work well in low light conditions.
  2. Does not work very well under substantial occlusion
  3. Does not work for side face and extreme non-frontal faces, like looking down or up.
  4. The pretrained model requires licensing for commercial use as described in https://github.com/davisking/dlib-models.

 

Building dependencies

It took a lot of time to build dependencies on BBAI: OpenCV 4.12, Numpy, dlib, scipy and others. I wish they were already preloaded on BB AI..

DNN

I was considering using the OpenCV DNN model as well, but I ran into some challenges: it requires a newer version of OpenCV than was provided with BBAI.I've built OpenCV 4.12, but I've got runtime errors when I tried to use its DNN model on BBAI.

BLE

I was planning on connecting my NXP BLE gas analyzer to detect if levels of CO2 and TVOC are unsafe. But I have not been able to make BLE operational on the current version of Linux kernel supported by BBAI. More details about the issue can be found at BBAI GitHub. And my plan to use BT speaker failed too. So I've decided to use a buzzer.

GPIO

Buzzer requires signal from GPIO. Python library for BB hasn't been updated to support BBAI. So it took some research to map pins.

Adding new capabilities

Head tilt

Detecting drowsiness by measuring eyes has some limitations. It is not very useful if the driver is wearing glasses. So I’ve added a new feature that measures head tilt. It allows to detect state, when the driver is distracted by a mobile phone.

Headless mode

I’ve added a new command line parameter that allows to run the program without a screen in a headless mode.

Capturing telemetry

It is quite useful to capture values of variables to analyze the behavior of the system, and to fine tune thresholds to trigger alarms.

 

Performance optimization

My web camera generates a 480p video stream of 30fps. I've implemented frame dropping in my DSM. It perform an analysis only once in three frames.

 

Auto-start

 

I've added an option to start DSM automatically after the boot as a service, so that it can be operated without the need to start it from terminal.

 

Reflection on initial tests

After doing several tests I realized that I need to implement several new capabilities to make it more practical.

Video stream calibration

This feature is to detect the face and crop unrelated space. It accelerates processing significantly and improves the reliability of face detection. It is now done automatically at the start of the DSM.

 

Tilt calibration
Tilt threshold can be different depending on the location of the camera and other factors. So it is now automatically calculated after several seconds.
Video recording

It is quite useful to review real tests. So I've added video recording capability to my DSM.

 

Testing Driver State Monitor with BeagleBone AI

Lab Test

The following video illustrates the working solution in my home lab. The first alarm gets generated on the 16th second when I start looking down, triggered by a head tilt, and another at the 31st second, when I closed my eyes. Be ready for a noisy buzzer!

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Test results

The following graph illustrates that the alarm (red line) was triggered by reaching the head tilt threshold in the first and by reaching the EAR threshold (closed eyes) in the second case.image

Test Drive

Here is my test setup in the car.

image

 

This video captured the real test drive of DSM, where results of processing got captured on video. The young driver did a great job and was focused on the road all times - no alerts where generated during the drive.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Components

I'm using the following components to implement this project:

Hardware
  • BBAI to detect and analyze the driver's face, eyes, and to check if they are open, if they are focused on the road or if the head is tilted and focused on a mobile phone. It was provided by Element14.
  • USB Webcam
  • Seeed studio buzzer
  • CPU fan F251R-05LLC.  It was provided by Element14.
Software
  • Debian (supplied with BBAI) kernel 4.14.x
  • Python 3.5
  • OpenCV 4 to process video stream
  • Dlib by Davis King to detect face and face landmarks

image

 

My ToDo list

  • Test the system in a car
  • Test with glasses
  • Test in low light condition
  • Publish code on GitHub
  • Improve reliability in low light conditions (may need to add IR Camera)
  • Improve performance by using EVE, c66x cores once TI releases support for OpenCV 3.3+ and DNN module.
  • Explore Tensorflow/Python integration with TIDL once it is available in Q1 2020
  • Add gas sensors once BLE support is implemented in BBAI
  • Add blue LED light in addition to buzzer
  • Set 10 fps mode on camera

 

 

Thank you for reading my blog!

  • Sign in to reply

Top Comments

  • dubbie
    dubbie over 3 years ago +5
    Looks like a good solution. There was a time I could have done with something like this. I used to commute 65 miles each way to work and sometimes after a 12 hour day, driving home on a dark winter night…
  • vimarsh_
    vimarsh_ over 3 years ago +5
    Will the camera be needed to mount in the front like on the dashboard or something? A great idea and if implemented on large scale it can save lots of lives
  • genebren
    genebren over 3 years ago in reply to dubbie +4
    I have been there and tried that before, just to keep awake. Not necessarily safe, but effective.
  • vlasov01
    vlasov01 over 3 years ago in reply to three-phase

    Thank you for the feedback!

    I was a bit surprised too. I believe it is a combination of good lightning conditions and a short distance between the camera and face.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • three-phase
    three-phase over 3 years ago

    Great project, that is pretty impressive as to how accurately the eyeballs are being tracked, given all the dead movement.

     

    Kind regards.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vlasov01
    vlasov01 over 3 years ago in reply to vimarsh_

    The dashboard can be an option to mount the camera. But  the windshield can be considered too.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vlasov01
    vlasov01 over 3 years ago in reply to dubbie

    I'm considering to add blue light in addition to buzzer as it suppresses melatonin production.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 3 years ago in reply to dubbie

    I have been there and tried that before, just to keep awake.  Not necessarily safe, but effective.

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube