Face detection is used in social networks, photo editors, video chats, smart captcha, time tracking programs - you can think of many more applications of this function.

Option number 1
A nice solution for face detection -
FaceDetector in PHP, uses OpenCV. FaceDetector works stably with different skin tones, low-quality photos, lots of faces, and people with glasses.
Work algorithm
Face recognition is based on the Viola-Jones method, Haar cascades (rectangular primitives) and the AdaBoost learning algorithm. Primitives - white and black rectangles of different sizes - are superimposed on the image, after which their convolution with the image is read. Read in detail about using the Haar cascades
here and
here .
Install FaceDetector
First you need to install the packages:
')
sudo apt-get install pkg-config python libjpeg62-dev libpng12-dev libtiff4-dev php-pear
Install
OpenCV :
sudo apt-get install libopencv-dev
Install Library:
pecl install facedetect
Make sure that php.ini has:
extension=facedetect.so
Application
FaceDetector has two main functions:
face_count and
face_detect for counting and defining faces, respectively. The file
haarcascade_frontalface_alt.xml needs to be moved from
/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml to the project folder.
Code example - faces a pink square around the face:
<?php function LoadJpeg($imgname) { $im = @imagecreatefromjpeg($imgname); if (!$im) { $im = imagecreate(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); imagestring($im, 1, 5, 5, "Error loading $imgname", $tc); } return $im; } $total= face_count($_GET['file'],'haarcascade_frontalface_alt.xml'); $ord= face_detect($_GET['file'],'haarcascade_frontalface_alt.xml'); $im = LoadJpeg($_GET['file']); $pink = imagecolorallocate($im, 255, 105, 180); if(count($ord) > 0) { foreach ($ord as $arr) { imagerectangle($im,$arr['x'] ,$arr['y'] , $arr['x']+$arr['w'], $arr['y']+$arr['h'], $pink); } } header('Content-Type: image/jpeg'); imagejpeg($im); imagedestroy($im); ?>

Option number 2
Option without using OpenCV. The PHP FaceDetection library finds only one face in a photo. To use, you need to download a
PHP script and paste it into your code.
An example of using the code - one circle around a green square:
<?php include "FaceDetector.php"; $face_detect = new Face_Detector('detection.dat'); $face_detect->face_detect('sample.jpg'); $face_detect->toJpeg(); $json = $face_detect->toJson(); $array = $face_detect->getFace(); ?>
The face can be found and immediately cut using the
cropFace () function:
<?php include "FaceDetector.php"; $face_detect = new Face_Detector('detection.dat'); $face_detect->face_detect('sample.jpg'); $face_detect->cropFace(); ?>
Option number 3
Another
library based on opencv. Python script to identify individuals.
First you need to download and install all the necessary packages (Python, Python, OpenCV, OpenCV data files):
sudo apt-get install python python-opencv libopencv-dev
And install the FaceDetect library:
sudo cp facedetect /usr/local/bin
Check for the presence of a face on the photo. Returns 0 if there is a face, and 2 if not:
exec('./facedetect -q path/to/image.jpg'); echo exec('echo $?');
An example of using the FaceDetect library in PHP:
At the entrance is a picture image.jpg, and at the exit a picture test.jpg with a face selected in a square.

You can try this method of identifying individuals
here . The algorithm shows
good results even in photos with many faces. Although sometimes gives out amazing things. For example,
here he identified two faces with Samuel L. Jackson. And
here - two faces of Pamela Anderson.
PS: and yes - the seals function
does not recognize .
Abstract
- Three libraries for identifying people in PHP: PHP script on OpenCV, PHP FaceDetection and Python script FaceDetect.
- The OpenCV FaceDetector library uses Haar cascades.
- PHP FaceDetection can only find one face in a photo.
- You can try how the python-script FaceDetect works here .