Implement dlib_vector_length to calculate the euclidean distance of the vectors
It not use the 'length' native versions of dlib, due I have to convert the array to the vector, which will take the same time, and then I will use the native method.
This commit is contained in:
@@ -24,12 +24,14 @@ if test "$PHP_PDLIB" != "no"; then
|
|||||||
PHP_ADD_LIBRARY(stdc++, 1, PDLIB_SHARED_LIBADD)
|
PHP_ADD_LIBRARY(stdc++, 1, PDLIB_SHARED_LIBADD)
|
||||||
PHP_SUBST(PDLIB_SHARED_LIBADD)
|
PHP_SUBST(PDLIB_SHARED_LIBADD)
|
||||||
|
|
||||||
pdlib_src_files="pdlib.cc \
|
pdlib_src_files="
|
||||||
src/chinese_whispers.cc \
|
pdlib.cc \
|
||||||
src/face_detection.cc \
|
src/chinese_whispers.cc \
|
||||||
src/face_landmark_detection.cc \
|
src/face_detection.cc \
|
||||||
src/face_recognition.cc \
|
src/face_landmark_detection.cc \
|
||||||
src/cnn_face_detection.cc "
|
src/face_recognition.cc \
|
||||||
|
src/cnn_face_detection.cc \
|
||||||
|
src/vector.cc"
|
||||||
|
|
||||||
AC_MSG_CHECKING(for pkg-config)
|
AC_MSG_CHECKING(for pkg-config)
|
||||||
if test ! -f "$PKG_CONFIG"; then
|
if test ! -f "$PKG_CONFIG"; then
|
||||||
|
|||||||
@@ -27,12 +27,14 @@ extern "C" {
|
|||||||
#include "php_ini.h"
|
#include "php_ini.h"
|
||||||
#include "ext/standard/info.h"
|
#include "ext/standard/info.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "php_pdlib.h"
|
#include "php_pdlib.h"
|
||||||
#include "src/chinese_whispers.h"
|
#include "src/chinese_whispers.h"
|
||||||
#include "src/face_detection.h"
|
#include "src/face_detection.h"
|
||||||
#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"
|
||||||
|
|
||||||
/* 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)
|
||||||
@@ -260,10 +262,11 @@ 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(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[] */
|
||||||
};
|
};
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|||||||
+1
-1
@@ -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.1" /* Replace with version number for your extension */
|
#define PHP_PDLIB_VERSION "1.0.2" /* Replace with version number for your extension */
|
||||||
|
|
||||||
#ifdef PHP_WIN32
|
#ifdef PHP_WIN32
|
||||||
# define PHP_PDLIB_API __declspec(dllexport)
|
# define PHP_PDLIB_API __declspec(dllexport)
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
#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(ZEND_NUM_ARGS(), "aa", &x_arg, &y_arg) == FAILURE) {
|
||||||
|
zend_throw_exception_ex(
|
||||||
|
zend_ce_exception,
|
||||||
|
0 TSRMLS_CC,
|
||||||
|
"Unable to parse arrays in dlib_vector_length");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
zval *elem_x, *elem_y;
|
||||||
|
double sum = 0.0;
|
||||||
|
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 TSRMLS_CC,
|
||||||
|
"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 += pow(Z_DVAL_P(elem_x) - Z_DVAL_P(elem_y), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_DOUBLE(sqrt(sum));
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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_INFO(0, x_arg)
|
||||||
|
ZEND_ARG_INFO(0, y_arg)
|
||||||
|
ZEND_END_ARG_INFO()
|
||||||
|
PHP_FUNCTION(dlib_vector_length);
|
||||||
|
|
||||||
|
#endif //PHP_DLIB_VECTOR_H
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
--TEST--
|
||||||
|
Basic tests for dlib_vector_length
|
||||||
|
--SKIPIF--
|
||||||
|
<?php if (!extension_loaded("pdlib")) print "skip"; ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
var_dump(dlib_vector_length([0.0, 0.0], [1.0, 0.0]));
|
||||||
|
var_dump(dlib_vector_length([0.0, 0.0, -1.0], [0.0, 0.0, 1.0]));
|
||||||
|
var_dump(dlib_vector_length([0.0, 2.5, 1.0], [0.0, 1.0, 1.0]));
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
float(1)
|
||||||
|
float(2)
|
||||||
|
float(1.5)
|
||||||
@@ -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