Compare commits
32 Commits
v1.0.2
...
staticdlib
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a084e928cb | ||
|
|
c30c365fbf | ||
|
|
8a3403eb25 | ||
|
|
72abdb152a | ||
|
|
202e41959d | ||
|
|
b45b4bc4be | ||
|
|
4c5e0c7ad1 | ||
|
|
9ec3ff4d04 | ||
|
|
866828b325 | ||
|
|
231ab7d88e | ||
|
|
c7f5fcc606 | ||
|
|
92a97cbde9 | ||
|
|
94bbcb9c6d | ||
|
|
cedaecc76b | ||
|
|
a31d3bc709 | ||
|
|
1153e3e2eb | ||
|
|
32f94d32b9 | ||
|
|
526fb725ce | ||
|
|
c7d57a7a1b | ||
|
|
9a86f95849 | ||
|
|
cf0ce5a01e | ||
|
|
d36a2de544 | ||
|
|
40a2bd60e4 | ||
|
|
912ab43641 | ||
|
|
8f424195e0 | ||
|
|
ba797b3c50 | ||
|
|
b70ff4eb17 | ||
|
|
45c0b7441a | ||
|
|
7d60446891 | ||
|
|
351bce6117 | ||
|
|
24d12358f2 | ||
|
|
b4f152f860 |
27
.github/workflows/ci.yml
vendored
Normal file
27
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
name: Build and Test
|
||||||
|
on: [push, pull_request]
|
||||||
|
jobs:
|
||||||
|
ubuntu:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
version: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout pdlib
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
- name: install-deps
|
||||||
|
run: sudo apt update -y && sudo apt install -y libopenblas-dev liblapack-dev
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{matrix.version}}
|
||||||
|
- name: phpize
|
||||||
|
run: phpize
|
||||||
|
- name: configure
|
||||||
|
run: ./configure
|
||||||
|
- name: make
|
||||||
|
run: make
|
||||||
|
- name: test
|
||||||
|
run: make test TESTS="--show-diff tests" || true
|
||||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "dlib"]
|
||||||
|
path = dlib
|
||||||
|
url = https://github.com/davisking/dlib
|
||||||
28
.travis.yml
Normal file
28
.travis.yml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
dist: bionic
|
||||||
|
|
||||||
|
sudo: false
|
||||||
|
|
||||||
|
language: php
|
||||||
|
|
||||||
|
php:
|
||||||
|
- 7.1
|
||||||
|
- 7.2
|
||||||
|
- 7.3
|
||||||
|
- 7.4
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- sudo sh -c 'echo "deb https://repo.delellis.com.ar bionic bionic" > /etc/apt/sources.list.d/20-pdlib.list'
|
||||||
|
- wget -qO - https://repo.delellis.com.ar/repo.gpg.key | sudo apt-key add -
|
||||||
|
- sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 762E3157
|
||||||
|
- sudo apt update
|
||||||
|
- sudo apt-get install libdlib-dev
|
||||||
|
- phpize
|
||||||
|
- ./configure --enable-debug
|
||||||
|
- make
|
||||||
|
- sudo make install
|
||||||
|
- echo "extension=pdlib.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
|
||||||
|
|
||||||
|
script:
|
||||||
|
- export TEST_PHP_EXECUTABLE=`which php`
|
||||||
|
- export NO_INTERACTION=1
|
||||||
|
- php run-tests.php -q --show-diff
|
||||||
@@ -36,6 +36,8 @@ git clone https://github.com/goodspb/pdlib.git
|
|||||||
cd pdlib
|
cd pdlib
|
||||||
phpize
|
phpize
|
||||||
./configure --enable-debug
|
./configure --enable-debug
|
||||||
|
# you may need to indicate the dlib install location
|
||||||
|
# PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure --enable-debug
|
||||||
make
|
make
|
||||||
sudo make install
|
sudo make install
|
||||||
```
|
```
|
||||||
|
|||||||
73
config.m4
73
config.m4
@@ -1,10 +1,3 @@
|
|||||||
dnl $Id$
|
|
||||||
dnl config.m4 for extension pdlib
|
|
||||||
|
|
||||||
dnl Comments in this file start with the string 'dnl'.
|
|
||||||
dnl Remove where necessary. This file will not work
|
|
||||||
dnl without editing.
|
|
||||||
|
|
||||||
if test -z "$PHP_DEBUG"; then
|
if test -z "$PHP_DEBUG"; then
|
||||||
AC_ARG_ENABLE(debug,
|
AC_ARG_ENABLE(debug,
|
||||||
[ --enable-debug compile with debugging symbols],[
|
[ --enable-debug compile with debugging symbols],[
|
||||||
@@ -17,39 +10,41 @@ PHP_ARG_WITH(pdlib, for pdlib support,
|
|||||||
dnl Make sure that the comment is aligned:
|
dnl Make sure that the comment is aligned:
|
||||||
[ --with-pdlib Include pdlib support])
|
[ --with-pdlib Include pdlib support])
|
||||||
|
|
||||||
if test "$PHP_PDLIB" != "no"; then
|
PHP_REQUIRE_CXX()
|
||||||
dnl using C++11
|
PHP_ADD_LIBRARY(stdc++, 1, PDLIB_SHARED_LIBADD)
|
||||||
CXXFLAGS="-std=c++11"
|
PHP_ADD_LIBRARY(openblas, 1, PDLIB_SHARED_LIBADD)
|
||||||
PHP_REQUIRE_CXX()
|
PHP_ADD_LIBRARY(lapack, 1, PDLIB_SHARED_LIBADD)
|
||||||
PHP_ADD_LIBRARY(stdc++, 1, PDLIB_SHARED_LIBADD)
|
PHP_ADD_LIBRARY(png, 1, PDLIB_SHARED_LIBADD)
|
||||||
PHP_SUBST(PDLIB_SHARED_LIBADD)
|
PHP_SUBST(PDLIB_SHARED_LIBADD)
|
||||||
|
|
||||||
pdlib_src_files="pdlib.cc \
|
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/dlib)
|
||||||
src/chinese_whispers.cc \
|
|
||||||
src/face_detection.cc \
|
|
||||||
src/face_landmark_detection.cc \
|
|
||||||
src/face_recognition.cc \
|
|
||||||
src/cnn_face_detection.cc "
|
|
||||||
|
|
||||||
AC_MSG_CHECKING(for pkg-config)
|
pdlib_src_files="pdlib.cc \
|
||||||
if test ! -f "$PKG_CONFIG"; then
|
dlib/dlib/all/source.cpp \
|
||||||
PKG_CONFIG=`which pkg-config`
|
src/chinese_whispers.cc \
|
||||||
fi
|
src/face_detection.cc \
|
||||||
|
src/face_landmark_detection.cc \
|
||||||
|
src/face_recognition.cc \
|
||||||
|
src/cnn_face_detection.cc \
|
||||||
|
src/vector.cc"
|
||||||
|
|
||||||
if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists dlib-1; then
|
dnl using C++11
|
||||||
if $PKG_CONFIG dlib-1 --atleast-version 19.00; then
|
CXXFLAGS="-g -O3 -march=native"
|
||||||
LIBDLIB_CFLAGS=`$PKG_CONFIG dlib-1 --cflags`
|
|
||||||
LIBDLIB_LIBDIR=`$PKG_CONFIG dlib-1 --libs`
|
|
||||||
LIBDLIB_VERSON=`$PKG_CONFIG dlib-1 --modversion`
|
|
||||||
AC_MSG_RESULT(from pkgconfig: dlib version $LIBDLIB_VERSON)
|
|
||||||
else
|
|
||||||
AC_MSG_ERROR(system dlib is too old: version 19.00 required)
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
AC_MSG_ERROR(pkg-config not found)
|
|
||||||
fi
|
|
||||||
PHP_EVAL_LIBLINE($LIBDLIB_LIBDIR, PDLIB_SHARED_LIBADD)
|
|
||||||
PHP_EVAL_INCLINE($LIBDLIB_CFLAGS)
|
|
||||||
|
|
||||||
PHP_NEW_EXTENSION(pdlib, $pdlib_src_files, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
|
PHP_NEW_EXTENSION(pdlib, $pdlib_src_files, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -DDLIB_NO_GUI_SUPPORT=1 -DDLIB_USE_BLAS -DDLIB_USE_LAPACK -DDLIB_PNG_SUPPORT, cxx)
|
||||||
fi
|
|
||||||
|
AC_CONFIG_COMMANDS_POST([
|
||||||
|
echo ""
|
||||||
|
echo "Build configuration for PDlib v1.1.0 done correctly."
|
||||||
|
echo ""
|
||||||
|
echo " dlib version: $LIBDLIB_VERSON"
|
||||||
|
echo ""
|
||||||
|
echo " CXXFLAGS : $CXXFLAGS"
|
||||||
|
echo " LDFLAGS : $LDFLAGS"
|
||||||
|
echo " LIBDIR: : $LIBDLIB_LIBDIR"
|
||||||
|
echo " LIBADD: : $PDLIB_SHARED_LIBADD"
|
||||||
|
echo ""
|
||||||
|
echo "Please submit bug reports at:"
|
||||||
|
echo " https://github.com/goodspb/pdlib/issues"
|
||||||
|
echo ""
|
||||||
|
])
|
||||||
1
dlib
Submodule
1
dlib
Submodule
Submodule dlib added at 70ea028f12
101
pdlib.cc
101
pdlib.cc
@@ -33,14 +33,14 @@ extern "C" {
|
|||||||
#include "src/face_recognition.h"
|
#include "src/face_recognition.h"
|
||||||
#include "src/cnn_face_detection.h"
|
#include "src/cnn_face_detection.h"
|
||||||
#include "src/face_landmark_detection.h"
|
#include "src/face_landmark_detection.h"
|
||||||
|
#include "src/vector.h"
|
||||||
|
|
||||||
|
//#include <dlib/revision.h>
|
||||||
|
|
||||||
/* If you declare any globals in php_pdlib.h uncomment this:
|
/* If you declare any globals in php_pdlib.h uncomment this:
|
||||||
ZEND_DECLARE_MODULE_GLOBALS(pdlib)
|
ZEND_DECLARE_MODULE_GLOBALS(pdlib)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* True global resources - no need for thread safety here */
|
|
||||||
static int le_pdlib;
|
|
||||||
|
|
||||||
static zend_class_entry *cnn_face_detection_ce = nullptr;
|
static zend_class_entry *cnn_face_detection_ce = nullptr;
|
||||||
static zend_object_handlers cnn_face_detection_obj_handlers;
|
static zend_object_handlers cnn_face_detection_obj_handlers;
|
||||||
|
|
||||||
@@ -60,34 +60,6 @@ PHP_INI_END()
|
|||||||
*/
|
*/
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* Remove the following function when you have successfully modified config.m4
|
|
||||||
so that your module can be compiled into PHP, it exists only for testing
|
|
||||||
purposes. */
|
|
||||||
|
|
||||||
/* Every user-visible function in PHP should document itself in the source */
|
|
||||||
/* {{{ proto string confirm_pdlib_compiled(string arg)
|
|
||||||
Return a string to confirm that the module is compiled in */
|
|
||||||
PHP_FUNCTION(confirm_pdlib_compiled)
|
|
||||||
{
|
|
||||||
char *arg = NULL;
|
|
||||||
size_t arg_len, len;
|
|
||||||
zend_string *strg;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
strg = strpprintf(0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "pdlib", arg);
|
|
||||||
|
|
||||||
RETURN_STR(strg);
|
|
||||||
}
|
|
||||||
/* }}} */
|
|
||||||
/* The previous line is meant for vim and emacs, so it can correctly fold and
|
|
||||||
unfold functions in source code. See the corresponding marks just before
|
|
||||||
function definition, where the functions purpose is also documented. Please
|
|
||||||
follow this convention for the convenience of others editing your code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* {{{ php_pdlib_init_globals
|
/* {{{ php_pdlib_init_globals
|
||||||
*/
|
*/
|
||||||
@@ -106,10 +78,10 @@ const zend_function_entry cnn_face_detection_class_methods[] = {
|
|||||||
PHP_FE_END
|
PHP_FE_END
|
||||||
};
|
};
|
||||||
|
|
||||||
zend_object* php_cnn_face_detection_new(zend_class_entry *class_type TSRMLS_DC)
|
zend_object* php_cnn_face_detection_new(zend_class_entry *class_type)
|
||||||
{
|
{
|
||||||
cnn_face_detection *cfd = (cnn_face_detection*)ecalloc(1, sizeof(cnn_face_detection));
|
cnn_face_detection *cfd = (cnn_face_detection*)ecalloc(1, sizeof(cnn_face_detection));
|
||||||
zend_object_std_init(&cfd->std, class_type TSRMLS_CC);
|
zend_object_std_init(&cfd->std, class_type);
|
||||||
object_properties_init(&cfd->std, class_type);
|
object_properties_init(&cfd->std, class_type);
|
||||||
cfd->std.handlers = &cnn_face_detection_obj_handlers; //zend_get_std_object_handlers();
|
cfd->std.handlers = &cnn_face_detection_obj_handlers; //zend_get_std_object_handlers();
|
||||||
|
|
||||||
@@ -129,10 +101,10 @@ const zend_function_entry face_landmark_detection_class_methods[] = {
|
|||||||
PHP_FE_END
|
PHP_FE_END
|
||||||
};
|
};
|
||||||
|
|
||||||
zend_object* php_face_landmark_detection_new(zend_class_entry *class_type TSRMLS_DC)
|
zend_object* php_face_landmark_detection_new(zend_class_entry *class_type)
|
||||||
{
|
{
|
||||||
face_landmark_detection *fld = (face_landmark_detection*)ecalloc(1, sizeof(face_landmark_detection));
|
face_landmark_detection *fld = (face_landmark_detection*)ecalloc(1, sizeof(face_landmark_detection));
|
||||||
zend_object_std_init(&fld->std, class_type TSRMLS_CC);
|
zend_object_std_init(&fld->std, class_type);
|
||||||
object_properties_init(&fld->std, class_type);
|
object_properties_init(&fld->std, class_type);
|
||||||
fld->std.handlers = &face_landmark_detection_obj_handlers;
|
fld->std.handlers = &face_landmark_detection_obj_handlers;
|
||||||
|
|
||||||
@@ -152,10 +124,10 @@ const zend_function_entry face_recognition_class_methods[] = {
|
|||||||
PHP_FE_END
|
PHP_FE_END
|
||||||
};
|
};
|
||||||
|
|
||||||
zend_object* php_face_recognition_new(zend_class_entry *class_type TSRMLS_DC)
|
zend_object* php_face_recognition_new(zend_class_entry *class_type)
|
||||||
{
|
{
|
||||||
face_recognition *fr = (face_recognition*)ecalloc(1, sizeof(face_recognition));
|
face_recognition *fr = (face_recognition*)ecalloc(1, sizeof(face_recognition));
|
||||||
zend_object_std_init(&fr->std, class_type TSRMLS_CC);
|
zend_object_std_init(&fr->std, class_type);
|
||||||
object_properties_init(&fr->std, class_type);
|
object_properties_init(&fr->std, class_type);
|
||||||
fr->std.handlers = &face_recognition_obj_handlers;
|
fr->std.handlers = &face_recognition_obj_handlers;
|
||||||
|
|
||||||
@@ -177,7 +149,7 @@ PHP_MINIT_FUNCTION(pdlib)
|
|||||||
// CnnFaceDetection class definition
|
// CnnFaceDetection class definition
|
||||||
//
|
//
|
||||||
INIT_CLASS_ENTRY(ce, "CnnFaceDetection", cnn_face_detection_class_methods);
|
INIT_CLASS_ENTRY(ce, "CnnFaceDetection", cnn_face_detection_class_methods);
|
||||||
cnn_face_detection_ce = zend_register_internal_class(&ce TSRMLS_CC);
|
cnn_face_detection_ce = zend_register_internal_class(&ce);
|
||||||
cnn_face_detection_ce->create_object = php_cnn_face_detection_new;
|
cnn_face_detection_ce->create_object = php_cnn_face_detection_new;
|
||||||
memcpy(&cnn_face_detection_obj_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
memcpy(&cnn_face_detection_obj_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
||||||
cnn_face_detection_obj_handlers.offset = XtOffsetOf(cnn_face_detection, std);
|
cnn_face_detection_obj_handlers.offset = XtOffsetOf(cnn_face_detection, std);
|
||||||
@@ -186,7 +158,7 @@ PHP_MINIT_FUNCTION(pdlib)
|
|||||||
// FaceLandmarkDetection class definition
|
// FaceLandmarkDetection class definition
|
||||||
//
|
//
|
||||||
INIT_CLASS_ENTRY(ce, "FaceLandmarkDetection", face_landmark_detection_class_methods);
|
INIT_CLASS_ENTRY(ce, "FaceLandmarkDetection", face_landmark_detection_class_methods);
|
||||||
face_landmark_detection_ce = zend_register_internal_class(&ce TSRMLS_CC);
|
face_landmark_detection_ce = zend_register_internal_class(&ce);
|
||||||
face_landmark_detection_ce->create_object = php_face_landmark_detection_new;
|
face_landmark_detection_ce->create_object = php_face_landmark_detection_new;
|
||||||
memcpy(&face_landmark_detection_obj_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
memcpy(&face_landmark_detection_obj_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
||||||
face_landmark_detection_obj_handlers.offset = XtOffsetOf(face_landmark_detection, std);
|
face_landmark_detection_obj_handlers.offset = XtOffsetOf(face_landmark_detection, std);
|
||||||
@@ -195,7 +167,7 @@ PHP_MINIT_FUNCTION(pdlib)
|
|||||||
// FaceRecognition class definition
|
// FaceRecognition class definition
|
||||||
//
|
//
|
||||||
INIT_CLASS_ENTRY(ce, "FaceRecognition", face_recognition_class_methods);
|
INIT_CLASS_ENTRY(ce, "FaceRecognition", face_recognition_class_methods);
|
||||||
face_recognition_ce = zend_register_internal_class(&ce TSRMLS_CC);
|
face_recognition_ce = zend_register_internal_class(&ce);
|
||||||
face_recognition_ce->create_object = php_face_recognition_new;
|
face_recognition_ce->create_object = php_face_recognition_new;
|
||||||
memcpy(&face_recognition_obj_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
memcpy(&face_recognition_obj_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
||||||
face_recognition_obj_handlers.offset = XtOffsetOf(face_recognition, std);
|
face_recognition_obj_handlers.offset = XtOffsetOf(face_recognition, std);
|
||||||
@@ -245,8 +217,53 @@ PHP_RSHUTDOWN_FUNCTION(pdlib)
|
|||||||
*/
|
*/
|
||||||
PHP_MINFO_FUNCTION(pdlib)
|
PHP_MINFO_FUNCTION(pdlib)
|
||||||
{
|
{
|
||||||
|
char buf[32];
|
||||||
|
|
||||||
php_info_print_table_start();
|
php_info_print_table_start();
|
||||||
php_info_print_table_header(2, "pdlib support", "enabled");
|
php_info_print_table_header(2, "pdlib support", "enabled");
|
||||||
|
php_info_print_table_row(2, "pdlib extension version", PHP_PDLIB_VERSION);
|
||||||
|
// snprintf(buf, sizeof(buf), "%d.%d.%d", DLIB_MAJOR_VERSION, DLIB_MINOR_VERSION, DLIB_PATCH_VERSION);
|
||||||
|
// php_info_print_table_row(2, "dlib library version", buf);
|
||||||
|
#ifdef DLIB_USE_CUDA
|
||||||
|
php_info_print_table_header(2, "DLIB_USE_CUDA", "true");
|
||||||
|
#else
|
||||||
|
php_info_print_table_header(2, "DLIB_USE_CUDA", "false");
|
||||||
|
#endif
|
||||||
|
#ifdef DLIB_USE_BLAS
|
||||||
|
php_info_print_table_header(2, "DLIB_USE_BLAS", "true");
|
||||||
|
#else
|
||||||
|
php_info_print_table_header(2, "DLIB_USE_BLAS", "false");
|
||||||
|
#endif
|
||||||
|
#ifdef DLIB_USE_LAPACK
|
||||||
|
php_info_print_table_header(2, "DLIB_USE_LAPACK", "true");
|
||||||
|
#else
|
||||||
|
php_info_print_table_header(2, "DLIB_USE_LAPACK", "false");
|
||||||
|
#endif
|
||||||
|
#ifdef DLIB_HAVE_AVX
|
||||||
|
php_info_print_table_header(2, "USE_AVX_INSTRUCTIONS", "true");
|
||||||
|
#else
|
||||||
|
php_info_print_table_header(2, "USE_AVX_INSTRUCTIONS", "false");
|
||||||
|
#endif
|
||||||
|
#ifdef DLIB_HAVE_AVX2
|
||||||
|
php_info_print_table_header(2, "USE_AVX2_INSTRUCTIONS", "true");
|
||||||
|
#else
|
||||||
|
php_info_print_table_header(2, "USE_AVX2_INSTRUCTIONS", "false");
|
||||||
|
#endif
|
||||||
|
#ifdef DLIB_HAVE_NEON
|
||||||
|
php_info_print_table_header(2, "USE_NEON_INSTRUCTIONS", "true");
|
||||||
|
#else
|
||||||
|
php_info_print_table_header(2, "USE_NEON_INSTRUCTIONS", "false");
|
||||||
|
#endif
|
||||||
|
#ifdef DLIB_HAVE_SSE2
|
||||||
|
php_info_print_table_header(2, "USE_SSE2_INSTRUCTIONS", "true");
|
||||||
|
#else
|
||||||
|
php_info_print_table_header(2, "USE_SSE2_INSTRUCTIONS", "false");
|
||||||
|
#endif
|
||||||
|
#ifdef DLIB_HAVE_SSE41
|
||||||
|
php_info_print_table_header(2, "USE_SSE4_INSTRUCTIONS", "true");
|
||||||
|
#else
|
||||||
|
php_info_print_table_header(2, "USE_SSE4_INSTRUCTIONS", "false");
|
||||||
|
#endif
|
||||||
php_info_print_table_end();
|
php_info_print_table_end();
|
||||||
|
|
||||||
/* Remove comments if you have entries in php.ini
|
/* Remove comments if you have entries in php.ini
|
||||||
@@ -260,10 +277,10 @@ PHP_MINFO_FUNCTION(pdlib)
|
|||||||
* Every user visible function must have an entry in pdlib_functions[].
|
* Every user visible function must have an entry in pdlib_functions[].
|
||||||
*/
|
*/
|
||||||
const zend_function_entry pdlib_functions[] = {
|
const zend_function_entry pdlib_functions[] = {
|
||||||
PHP_FE(confirm_pdlib_compiled, NULL)
|
|
||||||
PHP_FE(dlib_chinese_whispers, dlib_chinese_whispers_arginfo)
|
PHP_FE(dlib_chinese_whispers, dlib_chinese_whispers_arginfo)
|
||||||
PHP_FE(dlib_face_detection, dlib_face_detection_arginfo)
|
PHP_FE(dlib_face_detection, dlib_face_detection_arginfo)
|
||||||
PHP_FE(dlib_face_landmark_detection, dlib_face_landmark_detection_arginfo)
|
PHP_FE(dlib_face_landmark_detection, dlib_face_landmark_detection_arginfo)
|
||||||
|
PHP_FE(dlib_vector_length, dlib_vector_length_arginfo)
|
||||||
PHP_FE_END /* Must be the last line in pdlib_functions[] */
|
PHP_FE_END /* Must be the last line in pdlib_functions[] */
|
||||||
};
|
};
|
||||||
/* }}} */
|
/* }}} */
|
||||||
@@ -272,7 +289,7 @@ const zend_function_entry pdlib_functions[] = {
|
|||||||
*/
|
*/
|
||||||
zend_module_entry pdlib_module_entry = {
|
zend_module_entry pdlib_module_entry = {
|
||||||
STANDARD_MODULE_HEADER,
|
STANDARD_MODULE_HEADER,
|
||||||
"pdlib",
|
PHP_PDLIB_NAME,
|
||||||
pdlib_functions,
|
pdlib_functions,
|
||||||
PHP_MINIT(pdlib),
|
PHP_MINIT(pdlib),
|
||||||
PHP_MSHUTDOWN(pdlib),
|
PHP_MSHUTDOWN(pdlib),
|
||||||
|
|||||||
47
pecl/package.xml.in
Normal file
47
pecl/package.xml.in
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<package packagerversion="1.9.0" version="2.0"
|
||||||
|
xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0.xsd">
|
||||||
|
<name>pdlib</name>
|
||||||
|
<channel>pecl.php.net</channel>
|
||||||
|
<summary>PHP extension for Dlib</summary>
|
||||||
|
<description>
|
||||||
|
This extension provide some machine learning capability to php via Dlib.
|
||||||
|
</description>
|
||||||
|
<lead>
|
||||||
|
<name>Malvin Lok</name>
|
||||||
|
<user>goodspb</user>
|
||||||
|
<email>goodspb.luo@gmail.com</email>
|
||||||
|
<active>yes</active>
|
||||||
|
</lead>
|
||||||
|
<date>%RELEASE_DATE%</date>
|
||||||
|
<time>%RELEASE_TIME%</time>
|
||||||
|
<version>
|
||||||
|
<release>%RELEASE_VERSION%</release>
|
||||||
|
<api>%RELEASE_VERSION%</api>
|
||||||
|
</version>
|
||||||
|
<stability>
|
||||||
|
<release>%RELEASE_STABILITY%</release>
|
||||||
|
<api>%RELEASE_STABILITY%</api>
|
||||||
|
</stability>
|
||||||
|
<license uri="https://opensource.org/license/mit/">MIT</license>
|
||||||
|
<notes>
|
||||||
|
- Add native vector_lenght() function which calculates the euclidean distance 80% faster
|
||||||
|
</notes>
|
||||||
|
<contents>
|
||||||
|
%RELEASE_FILES%
|
||||||
|
</contents>
|
||||||
|
<dependencies>
|
||||||
|
<required>
|
||||||
|
<php>
|
||||||
|
<min>7.2.0</min>
|
||||||
|
</php>
|
||||||
|
<pearinstaller>
|
||||||
|
<min>1.4.0b1</min>
|
||||||
|
</pearinstaller>
|
||||||
|
</required>
|
||||||
|
</dependencies>
|
||||||
|
<providesextension>pdlib</providesextension>
|
||||||
|
<extsrcrelease />
|
||||||
|
</package>
|
||||||
162
pecl/prep-release.php
Normal file
162
pecl/prep-release.php
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
<?php
|
||||||
|
function verify_stability($stability) {
|
||||||
|
$stabilities = array(
|
||||||
|
"snapshot",
|
||||||
|
"devel",
|
||||||
|
"alpha",
|
||||||
|
"beta",
|
||||||
|
"stable",
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!in_array($stability, $stabilities)) {
|
||||||
|
echo "Invalid stability: $stability\n";
|
||||||
|
echo "Must be one of: ", join(", ", $stabilities), "\n";
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function verify_version($version, $stability) {
|
||||||
|
if (3 != sscanf($version, "%d.%d.%d", $major, $minor, $patch)) {
|
||||||
|
var_dump($major, $minor, $patch);
|
||||||
|
echo "Invalid version schema, expected 'major.minor.patch' (1.2.3), got $version\n";
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($major < 0 && $stability == "stable") {
|
||||||
|
echo "Invalid stability for major version $major ($stability)\n";
|
||||||
|
echo "Major versions before 1.0.0 cannot be marked as stable\n";
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_files() {
|
||||||
|
$dirs = array(
|
||||||
|
'src' => array(
|
||||||
|
"pdlib.cc",
|
||||||
|
"pdlib.php",
|
||||||
|
"php_pdlib.h",
|
||||||
|
"config.{m4,w32}",
|
||||||
|
"src/*.{cc,h}",
|
||||||
|
"dlib/**/*.{cpp,h}",
|
||||||
|
"dlib/**/**/*.{cpp,h}",
|
||||||
|
"dlib/**/**/**/*.{cpp,h}",
|
||||||
|
),
|
||||||
|
'test' => array(
|
||||||
|
"tests/*.{phpt}",
|
||||||
|
),
|
||||||
|
'doc' => array(
|
||||||
|
"README*",
|
||||||
|
"LICENSE",
|
||||||
|
"CREDITS",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$files = array();
|
||||||
|
foreach($dirs as $role => $patterns) {
|
||||||
|
foreach ($patterns as $pattern) {
|
||||||
|
foreach (glob($pattern, GLOB_BRACE) as $file) {
|
||||||
|
$files[$file] = $role;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ksort($files);
|
||||||
|
return $files;
|
||||||
|
}
|
||||||
|
|
||||||
|
function format_open_dir($dir, $tab) {
|
||||||
|
return sprintf('%s<dir name="%s">', str_repeat(" ", $tab), $dir);
|
||||||
|
}
|
||||||
|
function format_close_dir($tab) {
|
||||||
|
return sprintf("%s</dir>", str_repeat(" ", $tab));
|
||||||
|
}
|
||||||
|
function format_file($filename, $tab, $role) {
|
||||||
|
return sprintf('%s<file role="%s" name="%s"/>', str_repeat(" ", $tab+1), $role, $filename);
|
||||||
|
}
|
||||||
|
function make_tree($files) {
|
||||||
|
$retval = array();
|
||||||
|
$lastdir = ".";
|
||||||
|
$tab = 2;
|
||||||
|
|
||||||
|
$retval[] = format_open_dir("/", $tab);
|
||||||
|
foreach($files as $file => $role) {
|
||||||
|
$dir = dirname($file);
|
||||||
|
$filename = basename($file);
|
||||||
|
if ($dir != $lastdir) {
|
||||||
|
$currdir = explode("/", $dir);
|
||||||
|
$prevdir = explode("/", $lastdir);
|
||||||
|
foreach($currdir as $n => $d) {
|
||||||
|
if (isset($prevdir[$n]) && $prevdir[$n] == $d) {
|
||||||
|
/* In case we are shorter then previous */
|
||||||
|
$n++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ($lastdir != ".") {
|
||||||
|
foreach(array_reverse(array_slice($prevdir, $n)) as $close) {
|
||||||
|
$retval[] = format_close_dir($tab--);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach(array_slice($currdir, $n) as $open) {
|
||||||
|
$retval[] = format_open_dir($open, ++$tab);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$retval[] = format_file($filename, $tab, $role);
|
||||||
|
$lastdir = $dir;
|
||||||
|
}
|
||||||
|
foreach(array_reverse(explode("/", $lastdir)) as $close) {
|
||||||
|
$retval[] = format_close_dir($tab--);
|
||||||
|
}
|
||||||
|
$retval[] = format_close_dir($tab);
|
||||||
|
|
||||||
|
return $retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
function usage() {
|
||||||
|
global $argv;
|
||||||
|
|
||||||
|
echo "Usage:\n\t";
|
||||||
|
echo $argv[0], " <version> <stability>\n";
|
||||||
|
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($argc != 3) {
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
$VERSION = $argv[1];
|
||||||
|
$STABILITY = $argv[2];
|
||||||
|
|
||||||
|
/* 0.x.y. are developmental releases and cannot be stable */
|
||||||
|
if ((int)$VERSION < 1) {
|
||||||
|
$STABILITY = "devel";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A release candidate is a "beta" stability in terms of PECL */
|
||||||
|
if (stristr($VERSION, '-rc') !== false) {
|
||||||
|
$STABILITY = "beta";
|
||||||
|
}
|
||||||
|
|
||||||
|
verify_stability($STABILITY);
|
||||||
|
verify_version($VERSION, $STABILITY);
|
||||||
|
|
||||||
|
$currtime = new DateTime('now', new DateTimeZone('UTC'));
|
||||||
|
$DATE = $currtime->format('Y-m-d');
|
||||||
|
$TIME = $currtime->format('H:i:s');
|
||||||
|
|
||||||
|
$TREE = make_tree(get_files());
|
||||||
|
|
||||||
|
$contents = file_get_contents(__DIR__ . "/package.xml.in");
|
||||||
|
|
||||||
|
$REPLACE = array(
|
||||||
|
"%RELEASE_DATE%" => $DATE,
|
||||||
|
"%RELEASE_TIME%" => $TIME,
|
||||||
|
"%RELEASE_VERSION%" => $VERSION,
|
||||||
|
"%RELEASE_STABILITY%" => $STABILITY,
|
||||||
|
"%RELEASE_FILES%" => join("\n", $TREE),
|
||||||
|
);
|
||||||
|
|
||||||
|
$contents = str_replace(array_keys($REPLACE), array_values($REPLACE), $contents);
|
||||||
|
|
||||||
|
file_put_contents(__DIR__ . "/../package.xml", $contents);
|
||||||
|
echo "Wrote package.xml\n";
|
||||||
|
|
||||||
@@ -31,7 +31,8 @@ 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 "1.0.1" /* Replace with version number for your extension */
|
#define PHP_PDLIB_VERSION "1.1.0"
|
||||||
|
#define PHP_PDLIB_NAME "pdlib"
|
||||||
|
|
||||||
#ifdef PHP_WIN32
|
#ifdef PHP_WIN32
|
||||||
# define PHP_PDLIB_API __declspec(dllexport)
|
# define PHP_PDLIB_API __declspec(dllexport)
|
||||||
@@ -66,13 +67,13 @@ ZEND_TSRMLS_CACHE_EXTERN()
|
|||||||
/* Tries to find given key in array */ \
|
/* Tries to find given key in array */ \
|
||||||
data##key = zend_hash_str_find(hashtable, #key, sizeof(#key)-1); \
|
data##key = zend_hash_str_find(hashtable, #key, sizeof(#key)-1); \
|
||||||
if (data##key == nullptr) { \
|
if (data##key == nullptr) { \
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, #error_key_missing); \
|
zend_throw_exception_ex(zend_ce_exception, 0, #error_key_missing); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
/* We also need to check proper type of value in associative array */ \
|
/* We also need to check proper type of value in associative array */ \
|
||||||
if (Z_TYPE_P(data##key) != IS_LONG) { \
|
if (Z_TYPE_P(data##key) != IS_LONG) { \
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, #error_key_not_long); \
|
zend_throw_exception_ex(zend_ce_exception, 0, #error_key_not_long); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
zend_long key = Z_LVAL_P(data##key); \
|
zend_long key = Z_LVAL_P(data##key); \
|
||||||
|
|||||||
@@ -17,11 +17,7 @@ PHP_FUNCTION(dlib_chinese_whispers)
|
|||||||
std::vector<sample_pair> edges;
|
std::vector<sample_pair> edges;
|
||||||
std::vector<unsigned long> labels;
|
std::vector<unsigned long> labels;
|
||||||
|
|
||||||
if(zend_parse_parameters(ZEND_NUM_ARGS(), "a", &edges_arg) == FAILURE){
|
if(zend_parse_parameters_throw(ZEND_NUM_ARGS(), "a", &edges_arg) == FAILURE){
|
||||||
zend_throw_exception_ex(
|
|
||||||
zend_ce_exception,
|
|
||||||
0 TSRMLS_CC,
|
|
||||||
"Unable to parse edges in dlib_chinese_whispers");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +39,7 @@ PHP_FUNCTION(dlib_chinese_whispers)
|
|||||||
if (Z_TYPE_P(edge) != IS_ARRAY) {
|
if (Z_TYPE_P(edge) != IS_ARRAY) {
|
||||||
zend_throw_exception_ex(
|
zend_throw_exception_ex(
|
||||||
zend_ce_exception,
|
zend_ce_exception,
|
||||||
0 TSRMLS_CC,
|
0,
|
||||||
"Each edge provided in array needs to be numeric array of 2 elements");
|
"Each edge provided in array needs to be numeric array of 2 elements");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -55,7 +51,7 @@ PHP_FUNCTION(dlib_chinese_whispers)
|
|||||||
if (zend_hash_num_elements(edge_hash) != 2) {
|
if (zend_hash_num_elements(edge_hash) != 2) {
|
||||||
zend_throw_exception_ex(
|
zend_throw_exception_ex(
|
||||||
zend_ce_exception,
|
zend_ce_exception,
|
||||||
0 TSRMLS_CC,
|
0,
|
||||||
"Edges need to contain exactly two elements");
|
"Edges need to contain exactly two elements");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -66,7 +62,7 @@ PHP_FUNCTION(dlib_chinese_whispers)
|
|||||||
!zend_hash_index_exists(edge_hash, 1)) {
|
!zend_hash_index_exists(edge_hash, 1)) {
|
||||||
zend_throw_exception_ex(
|
zend_throw_exception_ex(
|
||||||
zend_ce_exception,
|
zend_ce_exception,
|
||||||
0 TSRMLS_CC,
|
0,
|
||||||
"Edge should be numeric array with integer keys");
|
"Edge should be numeric array with integer keys");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -78,7 +74,7 @@ PHP_FUNCTION(dlib_chinese_whispers)
|
|||||||
if ((Z_TYPE_P(elem_i) != IS_LONG) || (Z_TYPE_P(elem_j) != IS_LONG)) {
|
if ((Z_TYPE_P(elem_i) != IS_LONG) || (Z_TYPE_P(elem_j) != IS_LONG)) {
|
||||||
zend_throw_exception_ex(
|
zend_throw_exception_ex(
|
||||||
zend_ce_exception,
|
zend_ce_exception,
|
||||||
0 TSRMLS_CC,
|
0,
|
||||||
"Both elements in each edge must be of long type");
|
"Both elements in each edge must be of long type");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -97,7 +93,7 @@ PHP_FUNCTION(dlib_chinese_whispers)
|
|||||||
}
|
}
|
||||||
} catch (exception& e)
|
} catch (exception& e)
|
||||||
{
|
{
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
|
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#define PHP_DLIB_CHINESE_WHISPERS_H
|
#define PHP_DLIB_CHINESE_WHISPERS_H
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_INFO_EX(dlib_chinese_whispers_arginfo, 0, 0, 1)
|
ZEND_BEGIN_ARG_INFO_EX(dlib_chinese_whispers_arginfo, 0, 0, 1)
|
||||||
ZEND_ARG_INFO(0, edges)
|
ZEND_ARG_ARRAY_INFO(0, edges, 0)
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
PHP_FUNCTION(dlib_chinese_whispers);
|
PHP_FUNCTION(dlib_chinese_whispers);
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <zend_exceptions.h>
|
#include <zend_exceptions.h>
|
||||||
#include <dlib/image_processing/frontal_face_detector.h>
|
#include <dlib/image_processing/frontal_face_detector.h>
|
||||||
#include <dlib/gui_widgets.h>
|
|
||||||
#include <dlib/image_io.h>
|
#include <dlib/image_io.h>
|
||||||
#include <dlib/dnn.h>
|
#include <dlib/dnn.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -25,13 +24,12 @@ PHP_METHOD(CnnFaceDetection, __construct)
|
|||||||
cnn_face_detection *cfd = Z_CNN_FACE_DETECTION_P(getThis());
|
cnn_face_detection *cfd = Z_CNN_FACE_DETECTION_P(getThis());
|
||||||
|
|
||||||
if (NULL == cfd) {
|
if (NULL == cfd) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to find obj in CnnFaceDetection::__construct()");
|
php_error_docref(NULL, E_ERROR, "Unable to find obj in CnnFaceDetection::__construct()");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
|
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p",
|
||||||
&sz_cnn_face_detection_model_path, &cnn_face_detection_model_path_len) == FAILURE){
|
&sz_cnn_face_detection_model_path, &cnn_face_detection_model_path_len) == FAILURE){
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Unable to parse face_detection_model_path");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +40,7 @@ PHP_METHOD(CnnFaceDetection, __construct)
|
|||||||
deserialize(cnn_face_detection_model_path) >> *pnet;
|
deserialize(cnn_face_detection_model_path) >> *pnet;
|
||||||
cfd->net = pnet;
|
cfd->net = pnet;
|
||||||
} catch (exception& e) {
|
} catch (exception& e) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
|
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,8 +51,7 @@ PHP_METHOD(CnnFaceDetection, detect)
|
|||||||
size_t img_path_len;
|
size_t img_path_len;
|
||||||
long upsample_num = 0;
|
long upsample_num = 0;
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &img_path, &img_path_len, &upsample_num) == FAILURE){
|
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p|l", &img_path, &img_path_len, &upsample_num) == FAILURE){
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Unable to parse detect arguments");
|
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +74,6 @@ PHP_METHOD(CnnFaceDetection, detect)
|
|||||||
|
|
||||||
net_type *pnet = cfd->net;
|
net_type *pnet = cfd->net;
|
||||||
auto dets = (*pnet)(img);
|
auto dets = (*pnet)(img);
|
||||||
int rect_count = 0;
|
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
|
|
||||||
// Scale the detection locations back to the original image size
|
// Scale the detection locations back to the original image size
|
||||||
@@ -101,7 +97,7 @@ PHP_METHOD(CnnFaceDetection, detect)
|
|||||||
}
|
}
|
||||||
catch (exception& e)
|
catch (exception& e)
|
||||||
{
|
{
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
|
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,13 +23,17 @@ typedef struct _cnn_face_detection {
|
|||||||
} cnn_face_detection;
|
} cnn_face_detection;
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_INFO_EX(cnn_face_detection_ctor_arginfo, 0, 0, 1)
|
ZEND_BEGIN_ARG_INFO_EX(cnn_face_detection_ctor_arginfo, 0, 0, 1)
|
||||||
ZEND_ARG_INFO(0, cnn_face_detection_model_path)
|
ZEND_ARG_TYPE_INFO(0, cnn_face_detection_model_path, IS_STRING, 0)
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
PHP_METHOD(CnnFaceDetection, __construct);
|
PHP_METHOD(CnnFaceDetection, __construct);
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_INFO_EX(cnn_face_detection_detect_arginfo, 0, 0, 2)
|
ZEND_BEGIN_ARG_INFO_EX(cnn_face_detection_detect_arginfo, 0, 0, 1)
|
||||||
ZEND_ARG_INFO(0, img_path)
|
ZEND_ARG_TYPE_INFO(0, img_path, IS_STRING, 0)
|
||||||
ZEND_ARG_INFO(0, upsample_num)
|
#if PHP_VERSION_ID < 80000
|
||||||
|
ZEND_ARG_TYPE_INFO(0, upsample_num, IS_LONG, 0)
|
||||||
|
#else
|
||||||
|
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, upsample_num, IS_LONG, 0, "0")
|
||||||
|
#endif
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
PHP_METHOD(CnnFaceDetection, detect);
|
PHP_METHOD(CnnFaceDetection, detect);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include <zend_exceptions.h>
|
#include <zend_exceptions.h>
|
||||||
#include <dlib/image_processing/frontal_face_detector.h>
|
#include <dlib/image_processing/frontal_face_detector.h>
|
||||||
#include <dlib/gui_widgets.h>
|
|
||||||
#include <dlib/image_io.h>
|
#include <dlib/image_io.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -17,8 +16,7 @@ PHP_FUNCTION(dlib_face_detection)
|
|||||||
size_t img_path_len;
|
size_t img_path_len;
|
||||||
long upsample_num = 0;
|
long upsample_num = 0;
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &img_path, &img_path_len, &upsample_num) == FAILURE) {
|
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p|l", &img_path, &img_path_len, &upsample_num) == FAILURE) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Unable to parse dlib_face_detection arguments");
|
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -6,8 +6,12 @@
|
|||||||
#define PHP_DLIB_FACE_DETECTION_H
|
#define PHP_DLIB_FACE_DETECTION_H
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_INFO_EX(dlib_face_detection_arginfo, 0, 0, 1)
|
ZEND_BEGIN_ARG_INFO_EX(dlib_face_detection_arginfo, 0, 0, 1)
|
||||||
ZEND_ARG_INFO(0, img_path)
|
ZEND_ARG_TYPE_INFO(0, img_path, IS_STRING, 0)
|
||||||
ZEND_ARG_INFO(0, upsample_num)
|
#if PHP_VERSION_ID < 80000
|
||||||
|
ZEND_ARG_TYPE_INFO(0, upsample_num, IS_LONG, 0)
|
||||||
|
#else
|
||||||
|
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, upsample_num, IS_LONG, 0, "0")
|
||||||
|
#endif
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
PHP_FUNCTION(dlib_face_detection);
|
PHP_FUNCTION(dlib_face_detection);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <zend_exceptions.h>
|
#include <zend_exceptions.h>
|
||||||
|
|
||||||
#include <dlib/image_processing/frontal_face_detector.h>
|
#include <dlib/image_processing/frontal_face_detector.h>
|
||||||
#include <dlib/image_processing/render_face_detections.h>
|
|
||||||
#include <dlib/image_processing.h>
|
#include <dlib/image_processing.h>
|
||||||
#include <dlib/image_io.h>
|
#include <dlib/image_io.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -27,7 +26,7 @@ PHP_FUNCTION(dlib_face_landmark_detection)
|
|||||||
char *img_path;
|
char *img_path;
|
||||||
size_t shape_predictor_file_path_len, img_path_len;
|
size_t shape_predictor_file_path_len, img_path_len;
|
||||||
|
|
||||||
if(zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &shape_predictor_file_path, &shape_predictor_file_path_len,
|
if(zend_parse_parameters_throw(ZEND_NUM_ARGS(), "ss", &shape_predictor_file_path, &shape_predictor_file_path_len,
|
||||||
&img_path, &img_path_len) == FAILURE){
|
&img_path, &img_path_len) == FAILURE){
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
@@ -52,7 +51,7 @@ PHP_FUNCTION(dlib_face_landmark_detection)
|
|||||||
|
|
||||||
zval ARRAY_NAME_WITH_INDEX(face, j);
|
zval ARRAY_NAME_WITH_INDEX(face, j);
|
||||||
array_init(&ARRAY_NAME_WITH_INDEX(face, j));
|
array_init(&ARRAY_NAME_WITH_INDEX(face, j));
|
||||||
for (int k = 0; k < shape.num_parts(); k++) {
|
for (unsigned int k = 0; k < shape.num_parts(); k++) {
|
||||||
zval ARRAY_NAME_WITH_INDEX(part, k);
|
zval ARRAY_NAME_WITH_INDEX(part, k);
|
||||||
array_init(&ARRAY_NAME_WITH_INDEX(part, k));
|
array_init(&ARRAY_NAME_WITH_INDEX(part, k));
|
||||||
dlib::point p = shape.part(k);
|
dlib::point p = shape.part(k);
|
||||||
@@ -78,14 +77,13 @@ PHP_METHOD(FaceLandmarkDetection, __construct)
|
|||||||
face_landmark_detection *fld = Z_FACE_LANDMARK_DETECTION_P(getThis());
|
face_landmark_detection *fld = Z_FACE_LANDMARK_DETECTION_P(getThis());
|
||||||
|
|
||||||
if (nullptr == fld) {
|
if (nullptr == fld) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to find obj in FaceLandmarkDetection::__construct()");
|
php_error_docref(NULL, E_ERROR, "Unable to find obj in FaceLandmarkDetection::__construct()");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse predictor model's path
|
// Parse predictor model's path
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
|
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p",
|
||||||
&sz_shape_predictor_file_path, &shape_predictor_file_path_len) == FAILURE){
|
&sz_shape_predictor_file_path, &shape_predictor_file_path_len) == FAILURE){
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Unable to parse shape_predictor_file_path");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +93,7 @@ PHP_METHOD(FaceLandmarkDetection, __construct)
|
|||||||
fld->sp = new shape_predictor;
|
fld->sp = new shape_predictor;
|
||||||
deserialize(shape_predictor_file_path) >> *(fld->sp);
|
deserialize(shape_predictor_file_path) >> *(fld->sp);
|
||||||
} catch (exception& e) {
|
} catch (exception& e) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
|
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,8 +112,7 @@ PHP_METHOD(FaceLandmarkDetection, detect)
|
|||||||
|
|
||||||
// Parse path to image and bounding box. Bounding box is associative array of 4 elements - "top", "bottom", "left" and "right".
|
// Parse path to image and bounding box. Bounding box is associative array of 4 elements - "top", "bottom", "left" and "right".
|
||||||
//
|
//
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sa", &img_path, &img_path_len, &bounding_box) == FAILURE){
|
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "pa", &img_path, &img_path_len, &bounding_box) == FAILURE){
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Unable to parse detect arguments");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +120,7 @@ PHP_METHOD(FaceLandmarkDetection, detect)
|
|||||||
HashTable *bounding_box_hash = Z_ARRVAL_P(bounding_box);
|
HashTable *bounding_box_hash = Z_ARRVAL_P(bounding_box);
|
||||||
uint32_t bounding_box_num_elements = zend_hash_num_elements(bounding_box_hash);
|
uint32_t bounding_box_num_elements = zend_hash_num_elements(bounding_box_hash);
|
||||||
if (bounding_box_num_elements < 4) {
|
if (bounding_box_num_elements < 4) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Bounding box (second argument) needs to have at least 4 elements");
|
zend_throw_exception_ex(zend_ce_exception, 0, "Bounding box (second argument) needs to have at least 4 elements");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +148,7 @@ PHP_METHOD(FaceLandmarkDetection, detect)
|
|||||||
array_init(&rect_arr);
|
array_init(&rect_arr);
|
||||||
array_init(&parts_arr);
|
array_init(&parts_arr);
|
||||||
|
|
||||||
for (int i = 0; i < shape.num_parts(); i++) {
|
for (unsigned int i = 0; i < shape.num_parts(); i++) {
|
||||||
zval part;
|
zval part;
|
||||||
array_init(&part);
|
array_init(&part);
|
||||||
dlib::point p = shape.part(i);
|
dlib::point p = shape.part(i);
|
||||||
@@ -169,7 +166,7 @@ PHP_METHOD(FaceLandmarkDetection, detect)
|
|||||||
add_assoc_zval(return_value, "rect", &rect_arr);
|
add_assoc_zval(return_value, "rect", &rect_arr);
|
||||||
add_assoc_zval(return_value, "parts", &parts_arr);
|
add_assoc_zval(return_value, "parts", &parts_arr);
|
||||||
} catch (exception& e) {
|
} catch (exception& e) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
|
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
|
|
||||||
using namespace dlib;
|
using namespace dlib;
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_INFO_EX(dlib_face_landmark_detection_arginfo, 0, 0, 1)
|
ZEND_BEGIN_ARG_INFO_EX(dlib_face_landmark_detection_arginfo, 0, 0, 2)
|
||||||
ZEND_ARG_INFO(0, shape_predictor_file_path)
|
ZEND_ARG_TYPE_INFO(0, shape_predictor_file_path, IS_STRING, 0)
|
||||||
ZEND_ARG_INFO(0, img_path)
|
ZEND_ARG_TYPE_INFO(0, img_path, IS_STRING, 0)
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
PHP_FUNCTION(dlib_face_landmark_detection);
|
PHP_FUNCTION(dlib_face_landmark_detection);
|
||||||
|
|
||||||
@@ -21,13 +21,13 @@ typedef struct _face_landmark_detection {
|
|||||||
} face_landmark_detection;
|
} face_landmark_detection;
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_INFO_EX(face_landmark_detection_ctor_arginfo, 0, 0, 1)
|
ZEND_BEGIN_ARG_INFO_EX(face_landmark_detection_ctor_arginfo, 0, 0, 1)
|
||||||
ZEND_ARG_INFO(0, shape_predictor_file_path)
|
ZEND_ARG_TYPE_INFO(0, shape_predictor_file_path, IS_STRING, 0)
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
PHP_METHOD(FaceLandmarkDetection, __construct);
|
PHP_METHOD(FaceLandmarkDetection, __construct);
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_INFO_EX(face_landmark_detection_detect_arginfo, 0, 0, 2)
|
ZEND_BEGIN_ARG_INFO_EX(face_landmark_detection_detect_arginfo, 0, 0, 2)
|
||||||
ZEND_ARG_INFO(0, img_path)
|
ZEND_ARG_TYPE_INFO(0, img_path, IS_STRING, 0)
|
||||||
ZEND_ARG_INFO(0, bounding_box)
|
ZEND_ARG_ARRAY_INFO(0, bounding_box, 0)
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
PHP_METHOD(FaceLandmarkDetection, detect);
|
PHP_METHOD(FaceLandmarkDetection, detect);
|
||||||
|
|
||||||
|
|||||||
@@ -22,13 +22,12 @@ PHP_METHOD(FaceRecognition, __construct)
|
|||||||
face_recognition *fr = Z_FACE_RECOGNITION_P(getThis());
|
face_recognition *fr = Z_FACE_RECOGNITION_P(getThis());
|
||||||
|
|
||||||
if (NULL == fr) {
|
if (NULL == fr) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to find obj in FaceRecognition::__construct()");
|
php_error_docref(NULL, E_ERROR, "Unable to find obj in FaceRecognition::__construct()");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
|
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p",
|
||||||
&sz_face_recognition_model_path, &face_recognition_model_path_len) == FAILURE){
|
&sz_face_recognition_model_path, &face_recognition_model_path_len) == FAILURE){
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Unable to parse face_recognition_model_path");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +36,7 @@ PHP_METHOD(FaceRecognition, __construct)
|
|||||||
fr->net = new anet_type;
|
fr->net = new anet_type;
|
||||||
deserialize(face_recognition_model_path) >> *(fr->net);
|
deserialize(face_recognition_model_path) >> *(fr->net);
|
||||||
} catch (exception& e) {
|
} catch (exception& e) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
|
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,25 +72,24 @@ PHP_METHOD(FaceRecognition, computeDescriptor)
|
|||||||
zval *shape;
|
zval *shape;
|
||||||
long num_jitters = 1;
|
long num_jitters = 1;
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sa|l", &img_path, &img_path_len, &shape, &num_jitters) == FAILURE){
|
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "pa|l", &img_path, &img_path_len, &shape, &num_jitters) == FAILURE){
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Unable to parse computeDescriptor arguments");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashTable *shape_hash = Z_ARRVAL_P(shape);
|
HashTable *shape_hash = Z_ARRVAL_P(shape);
|
||||||
uint32_t shape_hash_num_elements = zend_hash_num_elements(shape_hash);
|
uint32_t shape_hash_num_elements = zend_hash_num_elements(shape_hash);
|
||||||
if (shape_hash_num_elements != 2) {
|
if (shape_hash_num_elements != 2) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Shape (second argument) needs to have exactly 2 elements - keys \"rect\" and \"parts\"");
|
zend_throw_exception_ex(zend_ce_exception, 0, "Shape (second argument) needs to have exactly 2 elements - keys \"rect\" and \"parts\"");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
zval *rect_zval = zend_hash_str_find(shape_hash, "rect", sizeof("rect")-1);
|
zval *rect_zval = zend_hash_str_find(shape_hash, "rect", sizeof("rect")-1);
|
||||||
if (rect_zval == nullptr) {
|
if (rect_zval == nullptr) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Shape (second argument) array needs to have \"rect\" key"); \
|
zend_throw_exception_ex(zend_ce_exception, 0, "Shape (second argument) array needs to have \"rect\" key"); \
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Z_TYPE_P(rect_zval) != IS_ARRAY) {
|
if (Z_TYPE_P(rect_zval) != IS_ARRAY) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Value of shape's key \"rect\" must be array");
|
zend_throw_exception_ex(zend_ce_exception, 0, "Value of shape's key \"rect\" must be array");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HashTable *rect_hash = Z_ARRVAL_P(rect_zval);
|
HashTable *rect_hash = Z_ARRVAL_P(rect_zval);
|
||||||
@@ -104,11 +102,11 @@ PHP_METHOD(FaceRecognition, computeDescriptor)
|
|||||||
|
|
||||||
zval *parts_zval = zend_hash_str_find(shape_hash, "parts", sizeof("parts")-1);
|
zval *parts_zval = zend_hash_str_find(shape_hash, "parts", sizeof("parts")-1);
|
||||||
if (parts_zval == nullptr) {
|
if (parts_zval == nullptr) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Shape (second argument) array needs to have \"parts\" key"); \
|
zend_throw_exception_ex(zend_ce_exception, 0, "Shape (second argument) array needs to have \"parts\" key"); \
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Z_TYPE_P(parts_zval) != IS_ARRAY) {
|
if (Z_TYPE_P(parts_zval) != IS_ARRAY) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Value of shape's key \"parts\" must be array");
|
zend_throw_exception_ex(zend_ce_exception, 0, "Value of shape's key \"parts\" must be array");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HashTable *parts_hash = Z_ARRVAL_P(parts_zval);
|
HashTable *parts_hash = Z_ARRVAL_P(parts_zval);
|
||||||
@@ -117,7 +115,7 @@ PHP_METHOD(FaceRecognition, computeDescriptor)
|
|||||||
point parts_points[parts_count];
|
point parts_points[parts_count];
|
||||||
|
|
||||||
if ((parts_count != 5) && (parts_count != 68)) {
|
if ((parts_count != 5) && (parts_count != 68)) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC,
|
zend_throw_exception_ex(zend_ce_exception, 0,
|
||||||
"The full_object_detection must use the iBUG 300W 68 point face landmark style or dlib's 5 point style");
|
"The full_object_detection must use the iBUG 300W 68 point face landmark style or dlib's 5 point style");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -137,17 +135,17 @@ PHP_METHOD(FaceRecognition, computeDescriptor)
|
|||||||
PARSE_POINT(x)
|
PARSE_POINT(x)
|
||||||
PARSE_POINT(y)
|
PARSE_POINT(y)
|
||||||
if (num_index > parts_count) {
|
if (num_index > parts_count) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Internal error, bad parsing of parts array");
|
zend_throw_exception_ex(zend_ce_exception, 0, "Internal error, bad parsing of parts array");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
parts_points[num_index] = point(x, y);
|
parts_points[num_index] = point(x, y);
|
||||||
} else {
|
} else {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Values from parts array must be arrays with \"x\" and \"y\" keys");
|
zend_throw_exception_ex(zend_ce_exception, 0, "Values from parts array must be arrays with \"x\" and \"y\" keys");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case HASH_KEY_IS_STRING:
|
case HASH_KEY_IS_STRING:
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, "Parts array must be indexed and it contains string keys");
|
zend_throw_exception_ex(zend_ce_exception, 0, "Parts array must be indexed and it contains string keys");
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -183,7 +181,7 @@ PHP_METHOD(FaceRecognition, computeDescriptor)
|
|||||||
add_next_index_double(return_value, d);
|
add_next_index_double(return_value, d);
|
||||||
}
|
}
|
||||||
} catch (exception& e) {
|
} catch (exception& e) {
|
||||||
zend_throw_exception_ex(zend_ce_exception, 0 TSRMLS_CC, e.what());
|
zend_throw_exception_ex(zend_ce_exception, 0, "%s", e.what());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,14 +44,18 @@ typedef struct _face_recognition {
|
|||||||
} face_recognition;
|
} face_recognition;
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_INFO_EX(face_recognition_ctor_arginfo, 0, 0, 1)
|
ZEND_BEGIN_ARG_INFO_EX(face_recognition_ctor_arginfo, 0, 0, 1)
|
||||||
ZEND_ARG_INFO(0, face_recognition_model_path)
|
ZEND_ARG_TYPE_INFO(0, face_recognition_model_path, IS_STRING, 0)
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
PHP_METHOD(FaceRecognition, __construct);
|
PHP_METHOD(FaceRecognition, __construct);
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_INFO_EX(face_recognition_compute_descriptor_arginfo, 0, 0, 3)
|
ZEND_BEGIN_ARG_INFO_EX(face_recognition_compute_descriptor_arginfo, 0, 0, 2)
|
||||||
ZEND_ARG_INFO(0, img_path)
|
ZEND_ARG_TYPE_INFO(0, img_path, IS_STRING, 0)
|
||||||
ZEND_ARG_INFO(0, landmarks)
|
ZEND_ARG_ARRAY_INFO(0, landmarks, 0)
|
||||||
ZEND_ARG_INFO(0, num_jitters)
|
#if PHP_VERSION_ID < 80000
|
||||||
|
ZEND_ARG_TYPE_INFO(0, num_jitters, IS_LONG, 0)
|
||||||
|
#else
|
||||||
|
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, num_jitters, IS_LONG, 0, "1")
|
||||||
|
#endif
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
PHP_METHOD(FaceRecognition, computeDescriptor);
|
PHP_METHOD(FaceRecognition, computeDescriptor);
|
||||||
|
|
||||||
|
|||||||
43
src/vector.cc
Normal file
43
src/vector.cc
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
#include "../php_pdlib.h"
|
||||||
|
|
||||||
|
#include "vector.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <zend_exceptions.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
PHP_FUNCTION(dlib_vector_length)
|
||||||
|
{
|
||||||
|
zval *x_arg, *y_arg;
|
||||||
|
|
||||||
|
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "aa", &x_arg, &y_arg) == FAILURE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
zval *elem_x, *elem_y;
|
||||||
|
double sum = 0.0;
|
||||||
|
unsigned int i, len;
|
||||||
|
|
||||||
|
len = zend_hash_num_elements(Z_ARRVAL_P(x_arg));
|
||||||
|
|
||||||
|
if (len != zend_hash_num_elements(Z_ARRVAL_P(y_arg))) {
|
||||||
|
zend_throw_exception_ex(
|
||||||
|
zend_ce_exception,
|
||||||
|
0,
|
||||||
|
"The arrays have different sizes");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0 ; i < len ; i++) {
|
||||||
|
elem_x = zend_hash_index_find(Z_ARRVAL_P(x_arg), i);
|
||||||
|
elem_y = zend_hash_index_find(Z_ARRVAL_P(y_arg), i);
|
||||||
|
|
||||||
|
sum += (Z_DVAL_P(elem_x) - Z_DVAL_P(elem_y))*(Z_DVAL_P(elem_x) - Z_DVAL_P(elem_y));
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_DOUBLE(sqrt(sum));
|
||||||
|
}
|
||||||
|
|
||||||
10
src/vector.h
Normal file
10
src/vector.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef PHP_DLIB_VECTOR_H
|
||||||
|
#define PHP_DLIB_VECTOR_H
|
||||||
|
|
||||||
|
ZEND_BEGIN_ARG_INFO_EX(dlib_vector_length_arginfo, 0, 0, 2)
|
||||||
|
ZEND_ARG_ARRAY_INFO(0, x_arg, 0)
|
||||||
|
ZEND_ARG_ARRAY_INFO(0, y_arg, 0)
|
||||||
|
ZEND_END_ARG_INFO()
|
||||||
|
PHP_FUNCTION(dlib_vector_length);
|
||||||
|
|
||||||
|
#endif //PHP_DLIB_VECTOR_H
|
||||||
@@ -6,10 +6,9 @@ Args given to chinese_whispers functions is not correct
|
|||||||
<?php
|
<?php
|
||||||
try {
|
try {
|
||||||
dlib_chinese_whispers("foo");
|
dlib_chinese_whispers("foo");
|
||||||
} catch (Exception $e) {
|
} catch (Error $e) {
|
||||||
var_dump($e->getMessage());
|
var_dump($e->getMessage());
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Warning: dlib_chinese_whispers() expects parameter 1 to be array, string given in %s on line 3
|
string(%d) "%s type array, string given"
|
||||||
string(46) "Unable to parse edges in dlib_chinese_whispers"
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ Testing CnnFaceDetection constructor without arguments
|
|||||||
<?php
|
<?php
|
||||||
try {
|
try {
|
||||||
new CnnFaceDetection();
|
new CnnFaceDetection();
|
||||||
} catch (Exception $e) {
|
} catch (Error $e) {
|
||||||
var_dump($e->getMessage());
|
var_dump($e->getMessage());
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Warning: CnnFaceDetection::__construct() expects exactly 1 parameter, 0 given in %s on line 3
|
string(%d) "CnnFaceDetection::__construct() expects exactly 1 %s, 0 given"
|
||||||
string(41) "Unable to parse face_detection_model_path"
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
--TEST--
|
--TEST--
|
||||||
Frontal face detection.
|
Frontal face detection.
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php if (!extension_loaded("pdlib") print "skip"; ?>
|
<?php
|
||||||
|
if (!extension_loaded("pdlib")) die('skip pdlib extension missing');
|
||||||
|
if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
|
||||||
|
?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
printf("Simple detection\n");
|
printf("Simple detection\n");
|
||||||
@@ -25,4 +28,4 @@ Faces found = 1
|
|||||||
Face[0] in bounding box (left=214, top=194, right=393, bottom=373)
|
Face[0] in bounding box (left=214, top=194, right=393, bottom=373)
|
||||||
Detection with upsampling
|
Detection with upsampling
|
||||||
Faces found = 1
|
Faces found = 1
|
||||||
Face[0] in bounding box (left=201, top=180, right=386, bottom=366)
|
Face[0] in bounding box (left=201, top=180, right=386, bottom=366)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Testing FaceLandmarkDetection constructor without arguments
|
|||||||
<?php
|
<?php
|
||||||
try {
|
try {
|
||||||
new FaceLandmarkDetection();
|
new FaceLandmarkDetection();
|
||||||
} catch (Exception $e) {
|
} catch (Error $e) {
|
||||||
var_dump($e->getMessage());
|
var_dump($e->getMessage());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -16,6 +16,5 @@ try {
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Warning: FaceLandmarkDetection::__construct() expects exactly 1 parameter, 0 given in %s on line 3
|
string(%d) "FaceLandmarkDetection::__construct() expects exactly 1 %s, 0 given"
|
||||||
string(41) "Unable to parse shape_predictor_file_path"
|
|
||||||
string(45) "Unable to open non-existent file for reading."
|
string(45) "Unable to open non-existent file for reading."
|
||||||
|
|||||||
@@ -6,10 +6,9 @@ Testing FaceRecognition constructor without arguments
|
|||||||
<?php
|
<?php
|
||||||
try {
|
try {
|
||||||
new FaceRecognition();
|
new FaceRecognition();
|
||||||
} catch (Exception $e) {
|
} catch (Error $e) {
|
||||||
var_dump($e->getMessage());
|
var_dump($e->getMessage());
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Warning: FaceRecognition::__construct() expects exactly 1 parameter, 0 given in %s on line 3
|
string(%d) "FaceRecognition::__construct() expects exactly 1 %s, 0 given"
|
||||||
string(43) "Unable to parse face_recognition_model_path"
|
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
--TEST--
|
--TEST--
|
||||||
Full test for face recognition - download models, detect faces, landmark detection and face recognition.
|
Full test for face recognition - download models, detect faces, landmark detection and face recognition.
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php if (!extension_loaded("pdlib") || (function_exists("bzopen"))) print "skip"; ?>
|
<?php
|
||||||
|
if (!extension_loaded("pdlib")) die('skip pdlib extension missing');
|
||||||
|
if (!function_exists("bzopen")) die('skip bz2 extension missing');
|
||||||
|
if (getenv("SKIP_ONLINE_TESTS")) die('skip online test');
|
||||||
|
?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
$models = array(
|
$models = array(
|
||||||
@@ -55,6 +59,6 @@ Processing prediction model
|
|||||||
Processing recognition model
|
Processing recognition model
|
||||||
Detection
|
Detection
|
||||||
Faces found = 1
|
Faces found = 1
|
||||||
Face[0] in bounding box (left=187, top=186, right=357, bottom=355)
|
Face[0] in bounding box (left=191, top=200, right=355, bottom=363)
|
||||||
Since we used model with 5 shape predictions, we found 5 landmark parts
|
Since we used model with 5 shape predictions, we found 5 landmark parts
|
||||||
Descriptor is vector of 128 dimensions
|
Descriptor is vector of 128 dimensions
|
||||||
|
|||||||
20
tests/vector_length.phpt
Normal file
20
tests/vector_length.phpt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
--TEST--
|
||||||
|
Basic tests for dlib_vector_length
|
||||||
|
--SKIPIF--
|
||||||
|
<?php if (!extension_loaded("pdlib")) print "skip"; ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$vectorAL = [0.0, 0.0];
|
||||||
|
$vectorAR = [0.0, 1.0];
|
||||||
|
var_dump(dlib_vector_length($vectorAL, $vectorAR));
|
||||||
|
$vectorBL = [0.0, 0.0, -1.0];
|
||||||
|
$vectorBR = [0.0, 0.0, 1.0];
|
||||||
|
var_dump(dlib_vector_length($vectorBL, $vectorBR));
|
||||||
|
$vectorCL = [0.0, 2.5, 1.0];
|
||||||
|
$vectorCR = [0.0, 1.0, 1.0];
|
||||||
|
var_dump(dlib_vector_length($vectorCL, $vectorCR));
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
float(1)
|
||||||
|
float(2)
|
||||||
|
float(1.5)
|
||||||
10
tests/version.phpt
Normal file
10
tests/version.phpt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
--TEST--
|
||||||
|
Just test php extension version
|
||||||
|
--SKIPIF--
|
||||||
|
<?php if (!extension_loaded("pdlib")) print "skip"; ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
var_dump(phpversion('pdlib'));
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(5) "1.0.2"
|
||||||
Reference in New Issue
Block a user