Majority of accidents happening in the country is mainly due to the usage of cell-phones or drowsiness. Travelling long distance or driving trucks and taxis for a long time every day and night can cause the driver to be sleep deprived and drowsy which can lead to accidents. With this project, we will be building a system using python and OpenCV that will detect the age and gender of the person and detect if there is any mobile phone in the vicinity. It also detects if the person is sleeping or not and will alarm the driver accordingly. With this project, we would like to reduce the number of accidents happening around us.
The goal of this paper is to develop a python code for safety of drivers, that detects the person’s age and gender. It detects if the person is sleeping by checking if the eyes are closed for a few seconds or using a mobile phone so as to ensure the safety of the driver by alarming the person.
Terms used in the project:
OpenCV: It is an open-source Computer Vision and Machine Learning library. This library is capable of processing real-time image and video. It supports the Deep Learning frameworks TensorFlow, Caffe, and PyTorch.
Face Recognition and object detection with OpenCV: A computer vision technology is face recognition. We discover and show human faces in any digital image using face recognition and detection. It is a subdomain of Object Detection, where we try to observe objects. These objects are of particular class such as humans, vehicles, animals etc.
CNN: A Convolutional Neural Network is a deep neural network widely used for the purposes of image recognition, image processing and NLP.
Gender and Age Detection: We will use Deep Learning to accurately identify the gender and age of a person from a single image of a face. We will use the models trained by Tal Hassner and Gil Levi. The predicted gender may be one of ‘Male’ and ‘Female’, and the predicted age may be one of the following ranges- (0 – 2), (4 – 6), (8 – 12), (15 – 20), (25 – 32), (38 – 43), (48 – 53), (60 – 100).
Numpy: Large, multi-dimensional arrays and matrices are supported in scientific computing via the Python software library known as NumPy. Numerous open-source software interfaces and contributors are present in NumPy.
Additionally, it includes the following:
a. A robust array object with N dimensions;
b. Broadcasting capabilities;
c. The ability to use tools to merge C/C++ and FORTRAN code.
For mathematical computations like linear algebra, the Fourier transform, etc., NumPy is helpful. Data size and type can be properly defined in numPy. NumPy allows provide quick integration with a variety of databases. Additionally, it is BSD-licensed, although with some limitations.
A. Gender and Age Detection
Two custom CNN layers are used for age group and gender estimation. The age group classification and gender classification trains the CNN layer over many images. These CNN layers can be implemented over OpenCV and can detect age and gender on live camera. The CNN using a Caffe deep learning framework
Using Caffe, there are 4 steps to training a CNN:
Step 1: The first step is data preparation, where we clean the photos and store them in a Caffe-compatible format. We'll create a Python script to take care of the pre-processing and storage of the images.
Step 2: A CNN architecture is selected in this stage, and its parameters are defined in a configuration file with the.prototxt extension.
Step 3: Model optimization is the responsibility of the solver. The solver parameters are specified in a configuration file with the.prototxt extension.
Step4: Training the model entails running a single Caffe command from the terminal. We will receive the trained model in a file with the extension when the model has been trained .caffemodel.
gender_net.caffemodel: It is the pre-trained model weights for gender detection.
deploy_gender.prototxt: is the model architecture for the gender detection model (a plain text file with a JSON-like structure
containing all the neural network layer’s definitions).
res10_300x300_ssd_iter_140000_fp16.caffemodel: The pre-trained model weights for face detection.
deploy.prototxt.txt: This is the model architecture for the face detection model.
B. Cellphone Detection
cv::dnn::DetectionModel Class is a Deep Neural Network module which we use to detect the cellphone after integrating it with OpenCV.
C. Face and Drowsiness Detection using Haar Classifier
A face detector known as a Haar Cascade classifier is used by OpenCV to identify drowsiness. The algorithm first requires an image with and without faces. The face detector looks at each picture point and labels it as "Face" or "Not Face," which is used to extract features. Two or three adjacent rectangles with varying contrast values combine to form the haar-like features. The camera placed in front of the driver begins to recognise the face and subsequently the eyes. The software will then take data from the webcam and determine whether the eyes are open or closed in order to detect sleepiness. The technology will play a loud alarm sound to rouse the driver up if their eyes are closed. The system will continue repeating the programme if the eyes are opened. Since the landmarks of the eyes are numbers 37 to 48, we used them for eye detection according to the Haar cascade 68 Landmarks pointers. Haar-like features have the potential for great accuracy and low expenditure. Hence with the help of this program, we can recognise whether the driver is drowsy or not and also provide a blaring alarm sound to warn the driver if sleeping.
We have developed a python code that runs successfully which ensures the safety of the drivers. It alarms when the person is sleeping or if it detects a mobile phone. It also displays the gender and the age of the person with about 80% accuracy. Haar-like features have the potential for great accuracy and low expenditure. In the future years, OpenCV will become quite well-known among python programmers in the IT industry.
 Chandan, G., Ayush Jain, and Harsh Jain. \"Real time object detection and tracking using Deep Learning and OpenCV.\" 2018 International Conference on inventive research in computing applications (ICIRCA). IEEE, 2018.
 Rajput, Bhumika. \"DRIVER DROWSINESS DETECTION USING PYTHON.\"
 Emami, Shervin, and Valentin Petrut Suciu. \"Facial recognition using OpenCV.\" Journal of Mobile, Embedded and Distributed Systems 4.1 (2012): 38-43..
 P. Reshvanth et al., \"Age Detection from Facial Images Using Python,\" 2021 Fifth International Conference on I-SMAC (IoT in Social, Mobile, Analytics and Cloud) (I-SMAC), 2021, pp. 1316-1321, doi: 10.1109/I-SMAC52330.2021.9641056.
 Saxena, Meghna Raj, et al. \"Real-time object detection using machine learning and opencv.\" Int J Inform Sci Appl (IJISA) 11.1 (2019): 0974-225.
 Khunpisuth, Oraan, et al. \"Driver drowsiness detection using eye-closeness detection.\" 2016 12th International Conference on Signal-Image Technology & Internet-Based Systems (SITIS). IEEE, 2016.
 Salihbaši?, Alen, and Tihomir Orehova?ki. \"Development of android application for gender, age and face recognition using opencv.\" 2019 42nd International Convention on Information and Communication Technology, Electronics and Microelectronics (MIPRO). IEEE, 2019.