Add native vector_lenght() function which calculates the euclidean distance 80%
faster. See https://github.com/matiasdelellis/pdlib/pull/2. Increase the version to 1.0.2 since this is a required function for our application and we must control it. Add more compilation info in php-info(), and print a final message with the build options when configure. Fix that when dlib is not installed, the configuration returns that it cannot find pkgconfig. See https://github.com/matiasdelellis/facerecognition/issues/261 Also implement the test on travis. See for example: (https://travis-ci.com/github/matiasdelellis/pdlib/builds/161854044)
This commit is contained in:
parent
c7d57a7a1b
commit
526fb725ce
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
|
42
config.m4
42
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],[
|
||||||
@ -27,26 +20,49 @@ if test "$PHP_PDLIB" != "no"; then
|
|||||||
src/face_detection.cc \
|
src/face_detection.cc \
|
||||||
src/face_landmark_detection.cc \
|
src/face_landmark_detection.cc \
|
||||||
src/face_recognition.cc \
|
src/face_recognition.cc \
|
||||||
src/cnn_face_detection.cc "
|
src/cnn_face_detection.cc
|
||||||
|
src/vector.cc"
|
||||||
|
|
||||||
AC_MSG_CHECKING(for pkg-config)
|
AC_MSG_CHECKING(for pkg-config)
|
||||||
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
|
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
|
||||||
|
if test -x "$PKG_CONFIG"; then
|
||||||
if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists dlib-1; then
|
AC_MSG_RESULT(found)
|
||||||
if $PKG_CONFIG dlib-1 --atleast-version 19.00; then
|
AC_MSG_CHECKING(for dlib-1)
|
||||||
|
if $PKG_CONFIG --exists dlib-1; then
|
||||||
|
if $PKG_CONFIG dlib-1 --atleast-version 19.00; then
|
||||||
LIBDLIB_CFLAGS=`$PKG_CONFIG dlib-1 --cflags`
|
LIBDLIB_CFLAGS=`$PKG_CONFIG dlib-1 --cflags`
|
||||||
LIBDLIB_LIBDIR=`$PKG_CONFIG dlib-1 --libs`
|
LIBDLIB_LIBDIR=`$PKG_CONFIG dlib-1 --libs`
|
||||||
LIBDLIB_VERSON=`$PKG_CONFIG dlib-1 --modversion`
|
LIBDLIB_VERSON=`$PKG_CONFIG dlib-1 --modversion`
|
||||||
AC_MSG_RESULT(from pkgconfig: dlib version $LIBDLIB_VERSON)
|
AC_MSG_RESULT(from pkgconfig: dlib version $LIBDLIB_VERSON)
|
||||||
else
|
else
|
||||||
AC_MSG_ERROR(system dlib is too old: version 19.00 required)
|
AC_MSG_ERROR(system dlib is too old: version 19.00 required)
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
AC_MSG_ERROR(dlib-1 not found)
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
AC_MSG_ERROR(pkg-config not found)
|
AC_MSG_ERROR(pkg-config not found)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PHP_EVAL_LIBLINE($LIBDLIB_LIBDIR, PDLIB_SHARED_LIBADD)
|
PHP_EVAL_LIBLINE($LIBDLIB_LIBDIR, PDLIB_SHARED_LIBADD)
|
||||||
PHP_EVAL_INCLINE($LIBDLIB_CFLAGS)
|
PHP_EVAL_INCLINE($LIBDLIB_CFLAGS)
|
||||||
|
|
||||||
dnl using C++11
|
dnl using C++11
|
||||||
PHP_NEW_EXTENSION(pdlib, $pdlib_src_files, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -std=c++11, cxx)
|
PHP_NEW_EXTENSION(pdlib, $pdlib_src_files, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -std=c++11, cxx)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
AC_CONFIG_COMMANDS_POST([
|
||||||
|
echo ""
|
||||||
|
echo "Build configuration for PDlib v1.0.2 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 ""
|
||||||
|
])
|
45
pdlib.cc
45
pdlib.cc
@ -33,6 +33,8 @@ 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>
|
#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:
|
||||||
@ -222,6 +224,46 @@ PHP_MINFO_FUNCTION(pdlib)
|
|||||||
php_info_print_table_row(2, "pdlib extension version", PHP_PDLIB_VERSION);
|
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);
|
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);
|
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
|
||||||
@ -238,6 +280,7 @@ const zend_function_entry pdlib_functions[] = {
|
|||||||
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[] */
|
||||||
};
|
};
|
||||||
/* }}} */
|
/* }}} */
|
||||||
@ -246,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),
|
||||||
|
@ -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.0.2"
|
||||||
|
#define PHP_PDLIB_NAME "pdlib"
|
||||||
|
|
||||||
#ifdef PHP_WIN32
|
#ifdef PHP_WIN32
|
||||||
# define PHP_PDLIB_API __declspec(dllexport)
|
# define PHP_PDLIB_API __declspec(dllexport)
|
||||||
|
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
|
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"
|
Loading…
Reference in New Issue
Block a user