Library for drowsiness detection using deep learning
Project description
This library uses deep learning to detect drowsiness of a person
Before using this library make sure you have installed following libraries which are needed
- Tensorflow
pip install tensorflow - keras
pip install keras - pyaudio
- For windows users
- First install pipwin
pip install pipwin - then install pyaudio it with
pipwin install pyaudio
- First install pipwin
- For linux users
sudo apt-get install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0 sudo apt-get install ffmpeg libav-tools sudo -s pip install pyaudio
- For windows users
- pyttsx3
pip install pyttsx3
To use this library just follow the steps
This library creates a new process by forking to perform predictions , but in windows process creation takes place differently by importing the script and executing it again so to avoid infinite loop initialize detector inside main condition as shown below
if __name__ == "__main__":
initialize the detector here
......
....
-
import it in your project
from DrowsinessDetection.DrowsinessDetector import getDetector -
initializing the detector
detector = getDetector()(Audio="path to audio file, completely optional",UseAssistant=True) -
starting the detector in separate thread
detector.start() -
Do any task and wait for detector to finish using this is a blocking call
detector.join()
if you want to listen for changing state of person then set a callback function which will take boolean as argument and this function will get fired every time person drowsy state changes , it will trigger true for sleeping and false for awake
def My_Callback(sleep):
print("recieved status sleeping --> "+str(sleep))
d = getDetector()(UseAssistant=True)
d.setCallbackForStateChange(My_Callback)
If you want to control the behaviour programmatically then there are few methods on detector object
- for setting sensitivity
detector.setSensitivity(any integer) - for closing the detector
detector.quit() - for observing state changes
detector.setCallbackForStateChange(My_Callback)
Use Voice Assistant to control the sensitivity of detector and for quiting
voice commands are
- sensitivity low
- sensitivity medium
- sensitivity high
- quit
one sample script
from DrowsinessDetection.DrowsinessDetector import getDetector
if __name__ == "__main__":
def My_Callback(sleep):
print("recieved "+str(sleep))
d = getDetector()(audio="audio-file-path",UseAssistant=True)
d.setCallbackForStateChange(My_Callback)
d.start()
d.join()
# press q to quit the script
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file python-DrowsyDetection-0.1.3.tar.gz.
File metadata
- Download URL: python-DrowsyDetection-0.1.3.tar.gz
- Upload date:
- Size: 30.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17ba1a0527e86b7e07b39ccf4f8cb832935ea5920a42067512b4ef643eb3994b
|
|
| MD5 |
bc2d51355c0e00cf7fb097a249729a2e
|
|
| BLAKE2b-256 |
739f388da1c32273c712b1bc005b6d0278743664e8e18cb80047b79157f5b0c7
|