From afc91641271bbd9dcf9384ddbd304291e1a03090 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Sat, 29 Feb 2020 14:04:41 -0300 Subject: [PATCH] HOG detector also must return the rectangles of the detections. --- .gitignore | 13 ++++++------- README.md | 5 ++--- php_pdlib.h | 2 +- src/face_detection.cc | 17 ++++++++++++++--- tests/dlib_face_detection.phpt | 18 ++++++++++++++++++ 5 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 tests/dlib_face_detection.phpt diff --git a/.gitignore b/.gitignore index 54983d3..2f6ab2a 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md index 81ca51b..f2a800e 100644 --- a/README.md +++ b/README.md @@ -100,9 +100,8 @@ If you want to use HOG based approach: img; load_image(img, img_path); - pyramid_up(img); + array_init(return_value); + std::vector 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) { diff --git a/tests/dlib_face_detection.phpt b/tests/dlib_face_detection.phpt new file mode 100644 index 0000000..8057bf4 --- /dev/null +++ b/tests/dlib_face_detection.phpt @@ -0,0 +1,18 @@ +--TEST-- +Frontal face detection. +--SKIPIF-- + +--FILE-- + $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) \ No newline at end of file