During the transportation of cargo and heavy materials over long distances (especially during night time) through trucks, the effects of inadequate sleep proves to be a major problem for these vehicle drivers involved in continuous driving, leading to fatal accidents. According to a 2014 AAA Traffic Safety Foundation study, it was found that 37 per cent of drivers fell asleep during driving . Out of the 21 per cent of fatal crashes, 13 per cent caused severe injury – all due to a drowsy driver who has to continuously drive for long time periods and at the same time, have an eye on the road.
So today, we are going to make a smart system that will keep track of a driver’s eye movement. If it detects that the driver might fall asleep or is in a drowsy state, then an alert is triggered in the form of a sound to bring that person back to conscious state.
What does our system do ?
A camera module connected to an RPi module continuously records video of the driver’s seat. A Python script then detects the face of the driver and when detected, the eyes of the person are captured and passed on to another module named eyegame, which then processes the captured video frame and detects the eye movement. If the eye of the driver remains at the same position without any movement or blinking, then an alarm sound will be triggered, asking the driver to stay awake and keep driving.
Bill of materials
We will also be needing an SD card for setting the Raspbian OS.
First of all we need to set up the library and modules in our RPi. To do so, open the Linux terminal and install the required modules using the following syntax and commands.
- sudo pip3 install install opencv
- sudo pip3 instal face-recognition
- sudo pip3 install espeak
- sudo pip3 instal eyegame
- sudo pip3 install delib
- sudo pip3 instal numpy
After successfully installing the modules, now create a Python code. I have named it eyetrack.py We will import all the required modules into the code.
Next, set the filename and path. This is needed because we want to capture and cut a specific frame from the video, and save it in that path, which will be passed to the eyegame for eye movement detection.
Next, we will set the face and image name of the truck driver and create a while function that will run in loop until the statement is true. Now we will capture the video from the camera by using OpenCV and cut the video frame-by-frame. It will then be passed to the face recognition module for detecting the face. If the recognised face is the same as the driver’s face, then it’s image will be saved in the path that we had previously created. Then we will call the eyegame module to analyse the eye and the eye ball movement.
By successfully detecting the face of the driver and the eye ball movement, the device will then repeatedly analyse the position of the eyeball. If no eye movement is detected, then the device will wait for 30 seconds. Even after that no eye movement is detected, then an audio will be set off to alert and wake up the driver. When the driver is awake and eye movement is detected, then the alert process will automatically stop.
After writing the entire code, connect the camera module with the Raspberry Pi, which is then connected to a speaker via an audio jack. Now run the script and wait for a few seconds. A window will appear on the screen that will be displaying a live video recording from the camera. By being present in front of the camera, your face and the eye movement and its position will be detected by the python terminal. If it detects that there is no eye movement, then it will start counting. After 30 seconds, a voice alert saying “Are You sleeping Start Driving” will be prompted.