/SafeDriving

🌺 RasberryPi+openCV Project

Primary LanguagePython

SafeDriving

💡 Algorithm
Detect eyes->Count time(when eyes closed)->if the count up to 3->alarm🔥

🙈 What we use
RasberryPi, opencv, webcam

🌼 How to install openCV in your RasberryPi

🔥 Make sure there's no opencv file exists in your RasberryPi

  1. Check your RasberryPi OS version
$ cat /etc/*release*

  1. Update any existing packages
$ sudo apt-get update
  1. Install some developer tools
$ sudo apt-get install build-essential cmake pkg-config
$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
$ sudo apt-get install libgtk2.0-dev
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install python2.7-dev python3-dev
  1. Download the openCV source code
$ cd ~
$ wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.1.0.zip
$ unzip opencv.zip
$ wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip
$ unzip opencv_contrib.zip

âš¡ I don't know why, but in my RasberryPi, I can get opencv-3.0.0 file when I do unzip opencv.zip
     Make sure the opencv_contrib and opencv file's version are the same
     So I just download the opencv file in window, and I import it by USB.

  1. Install pip
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
  1. Install numpy
$ pip install numpy
  1. Setup build using CMake
$ cd ~/opencv-3.1.0/
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules \
    -D BUILD_EXAMPLES=ON ..
  1. Build
$ make -j4

âš¡ It could take more than 2 hours, so just take a rest.

  1. Install openCV
$ sudo make install
$ sudo ldconfig
  1. Finish

🌼 Install several Libraries

  1. Install dlib prerequisites
$ sudo apt-get update
$ sudo apt-get install build-essential cmake
$ sudo apt-get install libgtk-3-dev
$ sudo apt-get install libboost-all-dev
  1. Use pip to install dlib with Python bindings
$ pip install scipy
$ pip install dlib

âš¡ It could take more than 2 hours, so just take a rest.

🌼 To run the code

🔥 Make sure haarcascade_frontalface_default.xml/shape_predictor_68_face_landmarks.dat files are in the same directory with thd code

python pi_detect_drowsiness.py --cascade haarcascade_frontalface_default.xml \
	--shape-predictor shape_predictor_68_face_landmarks.dat