HOG detector also must return the rectangles of the detections.

pull/1/head
Matias De lellis 5 years ago
parent 1e492f2e12
commit afc9164127

13
.gitignore vendored

@ -28,12 +28,11 @@ missing
mkinstalldirs
modules
run-tests.php
tests/*/*.diff
tests/*/*.out
tests/*/*.php
tests/*/*.exp
tests/*/*.log
tests/*/*.sh
tests/*.diff
tests/*.out
tests/*.php
tests/*.exp
tests/*.log
tests/*.sh
.idea
cmake-build-debug

@ -100,9 +100,8 @@ If you want to use HOG based approach:
<?php
// face detection
$faceCount = dlib_face_detection("~/a.jpg");
// how mary face in the picture.
var_dump($faceCount);
detected_faces = dlib_face_detection("image.jpg");
// $detected_faces is indexed array, where values are assoc arrays with "top", "bottom", "left" and "right" values
```
If you want to use CNN approach (and CNN model):

@ -31,7 +31,7 @@ extern "C" {
extern zend_module_entry pdlib_module_entry;
#define phpext_pdlib_ptr &pdlib_module_entry
#define PHP_PDLIB_VERSION "0.1.0" /* Replace with version number for your extension */
#define PHP_PDLIB_VERSION "1.0.1" /* Replace with version number for your extension */
#ifdef PHP_WIN32
# define PHP_PDLIB_API __declspec(dllexport)

@ -24,9 +24,20 @@ PHP_FUNCTION(dlib_face_detection)
array2d<unsigned char> img;
load_image(img, img_path);
pyramid_up(img);
array_init(return_value);
std::vector<rectangle> dets = detector(img);
RETURN_LONG(dets.size());
for (unsigned long i = 0; i < dets.size(); ++i) {
zval rect_arr;
array_init(&rect_arr);
add_assoc_long(&rect_arr, "left", dets[i].left());
add_assoc_long(&rect_arr, "top", dets[i].top());
add_assoc_long(&rect_arr, "right", dets[i].right());
add_assoc_long(&rect_arr, "bottom", dets[i].bottom());
// Add this assoc array to returned array
//
add_next_index_zval(return_value, &rect_arr);
}
}
catch (exception& e)
{

@ -0,0 +1,18 @@
--TEST--
Frontal face detection.
--SKIPIF--
<?php if (!extension_loaded("pdlib") print "skip"; ?>
--FILE--
<?php
printf("Detection\n");
$detected_faces = dlib_face_detection(__DIR__ . "/lenna.jpg");
printf("Faces found = %d\n", count($detected_faces));
foreach($detected_faces as $index => $detected_face) {
printf("Face[%d] in bounding box (left=%d, top=%d, right=%d, bottom=%d)\n", $index,
$detected_face["left"], $detected_face["top"], $detected_face["right"], $detected_face["bottom"]);
}
?>
--EXPECT--
Detection
Faces found = 1
Face[0] in bounding box (left=214, top=194, right=393, bottom=373)
Loading…
Cancel
Save