This Repository will explain my 4th task in Robotics and AI department at SMART METHODS summer training.
- Use OpenCV for making a real time face detection and recognition in Raspberry Pi.
-
Configure the Raspbeery Pi to control the controller remotely (Click Here).
-
Create your Python virtual environment and install NumPy then Compile OpenCV 4 from source (Click Here for full installation details).
-
Camera Test:
-
Test the camera using this Code in full details with commenet.
-
Run the virtual environment
workon cv
-
Open the path file if you have saved your .py file in a directory using
cd
command, in my case I will run the folowing commandcd Face_Recognition/Face_Detection
-
Run you camera test file by using
python
folowed by your file name, in my casepython Face_Detection.py
-
I will use a usb camera as shown in the figure:
-
Tested result will show an image in a Gray and RGB color:
-
-
Face Detection:
- To recognise a face first we should captutre the face (detecte it).The most common way used to detect a face or any objects, is using the "Haar Cascade classifier" (It is a machine learning based approach where a cascade function is trained from a lot of positive and negative images, It is then used to detect objects in other images).To detect faces the algorithm needs a lot of positive images (images of faces) and negative images (images without faces) to train the classifier. Then we need to extract features from it. OpenCV comes with a trainer as well as a detector. If we want to train our classifier for any object like car, planes etc. we can use OpenCV to create one using "Cascade Classifier Training".
- The good news is that OpenCV comes with a trainer as well as a detector and we will used it to detect faces. To see my code with comments, Click here.
- As shown in the figure below my face was detected successfully:
-
Face and Eye Detection:
- Now, lets detect the eyes of the face. To do that we should include the classifier for the eyes as we did in the face detection.
- Note that, on those cases, we will include the classifier function and rectangle draw inside the face loop, because there would be no sense to detect an eye outside of a face.
- To see my code with full comments, Click here.
- Tested Result:
-
Face Recognition