There are many algorithms out there that can be used for face detection. This article talks about one old one called the Haar Cascade which is an object detection algorithm. You can read more here
There are many more newer ones like Yolo which are more accurate, but one must give credit to this algorithm which comes from the pre-deep learning era for its speed.
OpenCV a computer vision library can perform out-of-the-box face detection using pre-trained Haar Cascades. To name a few the repo contains cascades for face detection, eye detection, etc. This project using the frontal face model.
Step1 - Install the Open CV library
#pip install opencv
Step 2 - Load the classifier
PLEASE NOTE - haarcascade_frontalface_default.xml which is saved locally
face_cascade = cv2.CascadeClassifier('face_detector.xml')
Step 3 - Make predictions using the classifier
PLEASE NOTE - parameters are the image, scalefactor and minimum neighbours. Refer the API docs
faces = face_cascade.detectMultiScale(img, 1.3, 3)
And you’re done with the last step which outlines boxes on the detected faces!!!
You may refer the full code here