💁‍♀️ Face Detection | Betabox

💁‍♀️ Face Detection

This next project will officially enter the field of computer vision!

Run the code

Once your car is connected to the router via ssh pi@raspberrypi.local on your terminal, type the following commands (pressing ‘enter’ after each input):

      cd vilib

      cd examples

      ls

Typing ls will show you all the files available in the folder you opened.

Now, type sudo python3 face_detect.py to launch the face detection and press enter.

On your terminal, you will see a link after “Running on:” Copy and paste that link on your browser to see the camera feed. The example below uses http://192.168.1.94:9000/mjpg

If you can, keep both windows open (split-screen) so you see the terminal page on one side and the car’s camera feed on the other, like this:

Whenever the camera detects a face, it will frame a blue rectangle around the face and the program will read how many faces are found.

Nice job. You’re the face of success! 


How does this work? 

This file uses a face detection model trained in OpenCV, which is an open source computer vision and machine learning software library. 

In a machine learning based approach, a cascade classifier is trained using many positive images (faces) and arbitrary negative images (without faces or objects). 

At each stage, the classifier examines the image using Haar-like features, which are specific patterns of intensity differences in the image that indicate the presence of a face. The classifier uses these features to make a decision about whether or not there is a face present in the image. If the classifier determines that there is likely a face present, it passes the image on to the next stage for further examination. If the classifier determines that there is not likely a face present, it rejects the image and the process ends.

In the image above, the middle feature focuses on the region of the eyes that is often darker than the region of the nose and cheeks. The feature on the right relies on the eyes being darker than the bridge of the nose.

Want to learn more? Explore this topic here.