Compare commits
15 Commits
develop
...
staticdlib
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a084e928cb | ||
|
|
c30c365fbf | ||
|
|
8a3403eb25 | ||
|
|
72abdb152a | ||
|
|
202e41959d | ||
|
|
b45b4bc4be | ||
|
|
4c5e0c7ad1 | ||
|
|
9ec3ff4d04 | ||
|
|
866828b325 | ||
|
|
231ab7d88e | ||
|
|
c7f5fcc606 | ||
|
|
92a97cbde9 | ||
|
|
94bbcb9c6d | ||
|
|
cedaecc76b | ||
|
|
a31d3bc709 |
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
|
||||||
@@ -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
|
||||||
```
|
```
|
||||||
|
|||||||
40
config.m4
40
config.m4
@@ -10,50 +10,32 @@ 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()
|
PHP_REQUIRE_CXX()
|
||||||
PHP_ADD_LIBRARY(stdc++, 1, PDLIB_SHARED_LIBADD)
|
PHP_ADD_LIBRARY(stdc++, 1, PDLIB_SHARED_LIBADD)
|
||||||
|
PHP_ADD_LIBRARY(openblas, 1, PDLIB_SHARED_LIBADD)
|
||||||
|
PHP_ADD_LIBRARY(lapack, 1, PDLIB_SHARED_LIBADD)
|
||||||
|
PHP_ADD_LIBRARY(png, 1, PDLIB_SHARED_LIBADD)
|
||||||
PHP_SUBST(PDLIB_SHARED_LIBADD)
|
PHP_SUBST(PDLIB_SHARED_LIBADD)
|
||||||
|
|
||||||
|
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/dlib)
|
||||||
|
|
||||||
pdlib_src_files="pdlib.cc \
|
pdlib_src_files="pdlib.cc \
|
||||||
|
dlib/dlib/all/source.cpp \
|
||||||
src/chinese_whispers.cc \
|
src/chinese_whispers.cc \
|
||||||
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"
|
src/vector.cc"
|
||||||
|
|
||||||
AC_MSG_CHECKING(for pkg-config)
|
|
||||||
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
|
|
||||||
if test -x "$PKG_CONFIG"; then
|
|
||||||
AC_MSG_RESULT(found)
|
|
||||||
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_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(dlib-1 not found)
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
AC_MSG_ERROR(pkg-config not found)
|
|
||||||
fi
|
|
||||||
|
|
||||||
PHP_EVAL_LIBLINE($LIBDLIB_LIBDIR, PDLIB_SHARED_LIBADD)
|
|
||||||
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)
|
CXXFLAGS="-g -O3 -march=native"
|
||||||
fi
|
|
||||||
|
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)
|
||||||
|
|
||||||
AC_CONFIG_COMMANDS_POST([
|
AC_CONFIG_COMMANDS_POST([
|
||||||
echo ""
|
echo ""
|
||||||
echo "Build configuration for PDlib v1.0.2 done correctly."
|
echo "Build configuration for PDlib v1.1.0 done correctly."
|
||||||
echo ""
|
echo ""
|
||||||
echo " dlib version: $LIBDLIB_VERSON"
|
echo " dlib version: $LIBDLIB_VERSON"
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
1
dlib
Submodule
1
dlib
Submodule
Submodule dlib added at 70ea028f12
6
pdlib.cc
6
pdlib.cc
@@ -35,7 +35,7 @@ extern "C" {
|
|||||||
#include "src/face_landmark_detection.h"
|
#include "src/face_landmark_detection.h"
|
||||||
#include "src/vector.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:
|
||||||
ZEND_DECLARE_MODULE_GLOBALS(pdlib)
|
ZEND_DECLARE_MODULE_GLOBALS(pdlib)
|
||||||
@@ -222,8 +222,8 @@ PHP_MINFO_FUNCTION(pdlib)
|
|||||||
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);
|
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
|
#ifdef DLIB_USE_CUDA
|
||||||
php_info_print_table_header(2, "DLIB_USE_CUDA", "true");
|
php_info_print_table_header(2, "DLIB_USE_CUDA", "true");
|
||||||
#else
|
#else
|
||||||
|
|||||||
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,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 "1.0.2"
|
#define PHP_PDLIB_VERSION "1.1.0"
|
||||||
#define PHP_PDLIB_NAME "pdlib"
|
#define PHP_PDLIB_NAME "pdlib"
|
||||||
|
|
||||||
#ifdef PHP_WIN32
|
#ifdef PHP_WIN32
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ try {
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
string(68) "CnnFaceDetection::__construct() expects exactly 1 parameter, 0 given"
|
string(%d) "CnnFaceDetection::__construct() expects exactly 1 %s, 0 given"
|
||||||
|
|
||||||
|
|||||||
@@ -16,5 +16,5 @@ try {
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
string(73) "FaceLandmarkDetection::__construct() expects exactly 1 parameter, 0 given"
|
string(%d) "FaceLandmarkDetection::__construct() expects exactly 1 %s, 0 given"
|
||||||
string(45) "Unable to open non-existent file for reading."
|
string(45) "Unable to open non-existent file for reading."
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ try {
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
string(67) "FaceRecognition::__construct() expects exactly 1 parameter, 0 given"
|
string(%d) "FaceRecognition::__construct() expects exactly 1 %s, 0 given"
|
||||||
|
|||||||
Reference in New Issue
Block a user