-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.php
executable file
·52 lines (42 loc) · 1.41 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
52
<?php
/**
* @file
* Use OpenCV's deep neural network module to detect faces in our dataset.
*/
// Include our Composer packages.
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require __DIR__ . '/vendor/autoload.php';
}
// Include custom classes.
require_once __DIR__ . '/../../FaceDetectionClient.php';
require_once __DIR__ . '/../../FaceDetectionImage.php';
require_once __DIR__ . '/../../FaceDetectionShell.php';
// Init our FaceDetectionClient class.
$app = new FaceDetection\FaceDetectionClient(basename(__DIR__), 'OpenCV - Deep learning', [255, 0, 0]);
// Initialize our client.
$cli = getenv('PYTHON_CLI');
$cli = $cli !== FALSE ? $cli : 'python';
$client = new FaceDetection\FaceDetectionShell($cli . ' detect_faces.py');
// 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) {
$x1 = $face['left'];
$y1 = $face['top'];
$x2 = $face['right'];
$y2 = $face['bottom'];
$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";