forked from php-opencv/php-opencv-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect_facemarks_by_lbf.php
34 lines (27 loc) · 955 Bytes
/
detect_facemarks_by_lbf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
use CV\CascadeClassifier, CV\Face\FacemarkLBF;
use function CV\{circle, imread, imwrite, cvtColor, equalizeHist};
use CV\Scalar;
use const CV\{COLOR_BGR2GRAY};
$src = imread("images/faces.jpg");
$gray = cvtColor($src, COLOR_BGR2GRAY);
equalizeHist($gray, $gray);
// face by lbpcascade_frontalface
$faceClassifier = new CascadeClassifier();
$faceClassifier->load('models/lbpcascades/lbpcascade_frontalface.xml');
$faces = null;
$faceClassifier->detectMultiScale($gray, $faces);
//var_export($faces);
$facemark = FacemarkLBF::create();
$facemark->loadModel('models/opencv-facemark-lbf/lbfmodel.yaml');
$facemark->fit($src, $faces, $landmarks);
//var_export($landmarks);
if ($landmarks) {
$scalar = new Scalar(0, 0, 255);
foreach ($landmarks as $face) {
foreach($face as $k => $point) {//var_export($point);
circle($src, $point, 2, $scalar, 2);
}
}
}
imwrite("results/_detect_facemarks_by_lbf.jpg", $src);