Face detection
Now, before we go ahead and detect faces, we need to tell the robot what a face is and what it looks like. Raspberry Pi does not know how exactly to classify a face from a pumpkin. So firstly, we would be using a dataset to tell the robot what our face looks like; thereafter, we will start recognizing the faces as we go. So let's go ahead and see how to do it.
Firstly, you need to install a dependency called Haar-cascade. This is a cascade-dependent algorithm that is used to detect objects rapidly. To do this, go ahead and run the following syntax on your terminal:
git clone https://github.com/opencv/opencv/tree/master/data/haarcascadesThis will save the haarcascades file onto your Raspberry Pi and you will be ready to use it. Once you are done, see the following code but write it over your Raspberry only after you have seen the following explanation line by line:
import cv2
import numpy as np
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap ...