first commit

This commit is contained in:
goodspb 2018-05-21 01:23:19 +08:00
commit 5539b5bff8
11 changed files with 450 additions and 0 deletions

38
.gitignore vendored Normal file
View File

@ -0,0 +1,38 @@
.deps
*.lo
*.la
.libs
acinclude.m4
aclocal.m4
autom4te.cache
build
config.guess
config.h
config.h.in
config.log
config.nice
config.status
config.sub
configure
configure.ac
include
install-sh
libtool
ltmain.sh
Makefile
Makefile.fragments
Makefile.global
Makefile.objects
missing
mkinstalldirs
modules
run-tests.php
tests/*/*.diff
tests/*/*.out
tests/*/*.php
tests/*/*.exp
tests/*/*.log
tests/*/*.sh
.idea
cmake-build-debug

1
CREDITS Normal file
View File

@ -0,0 +1 @@
pdlib

0
EXPERIMENTAL Normal file
View File

45
config.m4 Normal file
View File

@ -0,0 +1,45 @@
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.
dnl If your extension references something external, use with:
PHP_ARG_WITH(pdlib, for pdlib support,
dnl Make sure that the comment is aligned:
[ --with-pdlib Include pdlib support])
if test "$PHP_PDLIB" != "no"; then
dnl using C++11
CXXFLAGS="-std=c++11"
PHP_REQUIRE_CXX()
PHP_ADD_LIBRARY(stdc++, 1, DLIB_SHARED_LIBADD)
PHP_SUBST(DLIB_SHARED_LIBADD)
pdlib_src_files="pdlib.cc \
src/face_detection.cc"
AC_MSG_CHECKING(for pkg-config)
if test ! -f "$PKG_CONFIG"; then
PKG_CONFIG=`which pkg-config`
fi
if test -x "$PKG_CONFIG" && $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(pkg-config not found)
fi
PHP_EVAL_LIBLINE($LIBDLIB_LIBDIR, DLIB_SHARED_LIBADD)
PHP_EVAL_INCLINE($LIBDLIB_CFLAGS)
PHP_NEW_EXTENSION(pdlib, $pdlib_src_files, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
fi

13
config.w32 Normal file
View File

@ -0,0 +1,13 @@
// $Id$
// vim:ft=javascript
// If your extension references something external, use ARG_WITH
// ARG_WITH("pdlib", "for pdlib support", "no");
// Otherwise, use ARG_ENABLE
// ARG_ENABLE("pdlib", "enable pdlib support", "no");
if (PHP_PDLIB != "no") {
EXTENSION("pdlib", "pdlib.c", PHP_EXTNAME_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
}

188
pdlib.cc Normal file
View File

@ -0,0 +1,188 @@
/*
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2018 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: |
+----------------------------------------------------------------------+
*/
/* $Id$ */
extern "C" {
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
}
#include "php_pdlib.h"
#include "src/face_detection.h"
/* If you declare any globals in php_pdlib.h uncomment this:
ZEND_DECLARE_MODULE_GLOBALS(pdlib)
*/
/* True global resources - no need for thread safety here */
static int le_pdlib;
/* {{{ PHP_INI
*/
/* Remove comments and fill if you need to have entries in php.ini
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("pdlib.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_pdlib_globals, pdlib_globals)
STD_PHP_INI_ENTRY("pdlib.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_pdlib_globals, pdlib_globals)
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
*/
/* Uncomment this function if you have INI entries
static void php_pdlib_init_globals(zend_pdlib_globals *pdlib_globals)
{
pdlib_globals->global_value = 0;
pdlib_globals->global_string = NULL;
}
*/
/* }}} */
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(pdlib)
{
/* If you have INI entries, uncomment these lines
REGISTER_INI_ENTRIES();
*/
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(pdlib)
{
/* uncomment this line if you have INI entries
UNREGISTER_INI_ENTRIES();
*/
return SUCCESS;
}
/* }}} */
/* Remove if there's nothing to do at request start */
/* {{{ PHP_RINIT_FUNCTION
*/
PHP_RINIT_FUNCTION(pdlib)
{
#if defined(COMPILE_DL_PDLIB) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}
/* }}} */
/* Remove if there's nothing to do at request end */
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
PHP_RSHUTDOWN_FUNCTION(pdlib)
{
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(pdlib)
{
php_info_print_table_start();
php_info_print_table_header(2, "pdlib support", "enabled");
php_info_print_table_end();
/* Remove comments if you have entries in php.ini
DISPLAY_INI_ENTRIES();
*/
}
/* }}} */
/* {{{ pdlib_functions[]
*
* Every user visible function must have an entry in pdlib_functions[].
*/
const zend_function_entry pdlib_functions[] = {
PHP_FE(confirm_pdlib_compiled, NULL)
PHP_FE(dlib_face_detection, dlib_face_detection_arginfo)
PHP_FE_END /* Must be the last line in pdlib_functions[] */
};
/* }}} */
/* {{{ pdlib_module_entry
*/
zend_module_entry pdlib_module_entry = {
STANDARD_MODULE_HEADER,
"pdlib",
pdlib_functions,
PHP_MINIT(pdlib),
PHP_MSHUTDOWN(pdlib),
PHP_RINIT(pdlib), /* Replace with NULL if there's nothing to do at request start */
PHP_RSHUTDOWN(pdlib), /* Replace with NULL if there's nothing to do at request end */
PHP_MINFO(pdlib),
PHP_PDLIB_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_PDLIB
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
#endif
ZEND_GET_MODULE(pdlib)
#endif
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/

21
pdlib.php Normal file
View File

@ -0,0 +1,21 @@
<?php
$br = (php_sapi_name() == "cli")? "":"<br>";
if(!extension_loaded('pdlib')) {
dl('pdlib.' . PHP_SHLIB_SUFFIX);
}
$module = 'pdlib';
$functions = get_extension_funcs($module);
echo "Functions available in the test extension:$br\n";
foreach($functions as $func) {
echo $func."$br\n";
}
echo "$br\n";
$function = 'confirm_' . $module . '_compiled';
if (extension_loaded($module)) {
$str = $function($module);
} else {
$str = "Module $module is not compiled into PHP";
}
echo "$str\n";
?>

74
php_pdlib.h Normal file
View File

@ -0,0 +1,74 @@
/*
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2018 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef PHP_PDLIB_H
#define PHP_PDLIB_H
extern "C" {
#include "php.h"
#ifdef ZTS
#include "TSRM.h"
#endif
};
extern zend_module_entry pdlib_module_entry;
#define phpext_pdlib_ptr &pdlib_module_entry
#define PHP_PDLIB_VERSION "0.1.0" /* Replace with version number for your extension */
#ifdef PHP_WIN32
# define PHP_PDLIB_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
# define PHP_PDLIB_API __attribute__ ((visibility("default")))
#else
# define PHP_PDLIB_API
#endif
/*
Declare any global variables you may need between the BEGIN
and END macros here:
ZEND_BEGIN_MODULE_GLOBALS(pdlib)
zend_long global_value;
char *global_string;
ZEND_END_MODULE_GLOBALS(pdlib)
*/
/* Always refer to the globals in your function as PDLIB_G(variable).
You are encouraged to rename these macros something shorter, see
examples in any other php module directory.
*/
#define PDLIB_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(pdlib, v)
#if defined(ZTS) && defined(COMPILE_DL_PDLIB)
ZEND_TSRMLS_CACHE_EXTERN()
#endif
#endif /* PHP_PDLIB_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/

36
src/face_detection.cc Normal file
View File

@ -0,0 +1,36 @@
#include "../php_pdlib.h"
#include "face_detection.h"
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <iostream>
using namespace dlib;
using namespace std;
PHP_FUNCTION(dlib_face_detection)
{
char *img_path;
size_t img_path_len;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "s", &img_path, &img_path_len) == FAILURE){
RETURN_FALSE;
}
try {
frontal_face_detector detector = get_frontal_face_detector();
array2d<unsigned char> img;
load_image(img, img_path);
pyramid_up(img);
std::vector<rectangle> dets = detector(img);
RETURN_LONG(dets.size());
}
catch (exception& e)
{
RETURN_FALSE;
}
}

13
src/face_detection.h Normal file
View File

@ -0,0 +1,13 @@
//
// Created by goodspb on 2018/5/20.
//
#ifndef PHP_DLIB_FACE_DETECTION_H
#define PHP_DLIB_FACE_DETECTION_H
ZEND_BEGIN_ARG_INFO_EX(dlib_face_detection_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, img_path)
ZEND_END_ARG_INFO()
PHP_FUNCTION(dlib_face_detection);
#endif //PHP_DLIB_FACE_DETECTION_H

21
tests/001.phpt Normal file
View File

@ -0,0 +1,21 @@
--TEST--
Check for pdlib presence
--SKIPIF--
<?php if (!extension_loaded("pdlib")) print "skip"; ?>
--FILE--
<?php
echo "pdlib extension is available";
/*
you can add regression tests for your extension here
the output of your test code has to be equal to the
text in the --EXPECT-- section below for the tests
to pass, differences between the output and the
expected text are interpreted as failure
see php7/README.TESTING for further information on
writing regression tests
*/
?>
--EXPECT--
pdlib extension is available