-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.php
executable file
·51 lines (40 loc) · 1.47 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* @file
* Use Microsoft Azure Face to detect faces in our dataset.
*/
// Include our Composer packages.
require __DIR__ . '/vendor/autoload.php';
// Include custom classes.
require_once __DIR__ . '/../../FaceDetectionClient.php';
require_once __DIR__ . '/../../FaceDetectionImage.php';
require_once __DIR__ . '/MicrosoftFaceAPI.php';
// Init our FaceDetectionClient class.
$app = new FaceDetection\FaceDetectionClient(basename(__DIR__), 'Microsoft', [127, 186, 0]);
// Initialize the Amazon Rekognition client.
$client = new MicrosoftFaceAPI(getenv('MICROSOFT_AZURE_SUBSCRIPTION_KEY'));
// Load our dataset.
$images = $app->loadImages();
// Detect faces in our dataset.
foreach ($images as &$image) {
$app->startTimer();
$faces = $client->detectFaces($image);
$image->setProcessingTime($app->stopTimer());
if (!empty($faces)) {
foreach ($faces as $face) {
if (!empty($face['faceRectangle'])) {
$x1 = $face['faceRectangle']['left'];
$y1 = $face['faceRectangle']['top'];
$x2 = $face['faceRectangle']['left'] + $face['faceRectangle']['width'];
$y2 = $face['faceRectangle']['top'] + $face['faceRectangle']['height'];
$image->drawBoundingBox($x1, $y1, $x2, $y2);
$image->increaseDetectedFaceCount();
}
}
}
// Save our image.
$image->save();
}
// Add analytical data to our CSV file.
$app->exportCSV();
print 'Finished parsing dataset, found [' . $app->getTotalDetectedFaceCount() . '] faces.' . "\n";