HOG detector also must return the rectangles of the detections.

This commit is contained in:
Matias De lellis 2020-02-29 14:04:41 -03:00
parent 1e492f2e12
commit afc9164127
5 changed files with 41 additions and 14 deletions

13
.gitignore vendored
View File

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

View File

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

View File

@ -31,7 +31,7 @@ extern "C" {
extern zend_module_entry pdlib_module_entry; extern zend_module_entry pdlib_module_entry;
#define phpext_pdlib_ptr &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 #ifdef PHP_WIN32
# define PHP_PDLIB_API __declspec(dllexport) # define PHP_PDLIB_API __declspec(dllexport)

View File

@ -15,7 +15,7 @@ PHP_FUNCTION(dlib_face_detection)
char *img_path; char *img_path;
size_t img_path_len; size_t img_path_len;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &img_path, &img_path_len) == FAILURE){ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &img_path, &img_path_len) == FAILURE) {
RETURN_FALSE; RETURN_FALSE;
} }
try { try {
@ -24,9 +24,20 @@ PHP_FUNCTION(dlib_face_detection)
array2d<unsigned char> img; array2d<unsigned char> img;
load_image(img, img_path); load_image(img, img_path);
pyramid_up(img); array_init(return_value);
std::vector<rectangle> dets = detector(img); 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) catch (exception& e)
{ {

View File

@ -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)