Face recognition

This change adds support to retrieve 128D face descriptor for a given
landmark. Since now we have full pipeline, README.md has "general usage"
section and integration test is added. Also, return from
FaceLandmarkDetection is changed, so it can be given to FaceRecognition
without changes. All obtained values are crosschecked to match with values
from python versions (however, if num_jitters is > 1 in FaceRecognition,
values don't match between PHP and Python, I suspect it is related to usage
of dlib::rand, but still investigating)..
This commit is contained in:
Branko Kokanovic
2018-08-29 00:31:57 +02:00
parent 1a402fc63c
commit 1e830a3285
11 changed files with 468 additions and 32 deletions
+36
View File
@@ -30,6 +30,7 @@ extern "C" {
#include "php_pdlib.h"
#include "src/chinese_whispers.h"
#include "src/face_detection.h"
#include "src/face_recognition.h"
#include "src/cnn_face_detection.h"
#include "src/face_landmark_detection.h"
@@ -46,6 +47,9 @@ static zend_object_handlers cnn_face_detection_obj_handlers;
static zend_class_entry *face_landmark_detection_ce = nullptr;
static zend_object_handlers face_landmark_detection_obj_handlers;
static zend_class_entry *face_recognition_ce = nullptr;
static zend_object_handlers face_recognition_obj_handlers;
/* {{{ PHP_INI
*/
/* Remove comments and fill if you need to have entries in php.ini
@@ -142,6 +146,29 @@ static void php_face_landmark_detection_free(zend_object *object)
zend_object_std_dtor(object);
}
const zend_function_entry face_recognition_class_methods[] = {
PHP_ME(FaceRecognition, __construct, face_recognition_ctor_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(FaceRecognition, computeDescriptor, face_recognition_compute_descriptor_arginfo, ZEND_ACC_PUBLIC)
PHP_FE_END
};
zend_object* php_face_recognition_new(zend_class_entry *class_type TSRMLS_DC)
{
face_recognition *fr = (face_recognition*)ecalloc(1, sizeof(face_recognition));
zend_object_std_init(&fr->std, class_type TSRMLS_CC);
object_properties_init(&fr->std, class_type);
fr->std.handlers = &face_recognition_obj_handlers;
return &fr->std;
}
static void php_face_recognition_free(zend_object *object)
{
face_recognition *fr = (face_recognition*)((char*)object - XtOffsetOf(face_recognition, std));
delete fr->net;
zend_object_std_dtor(object);
}
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(pdlib)
@@ -165,6 +192,15 @@ PHP_MINIT_FUNCTION(pdlib)
face_landmark_detection_obj_handlers.offset = XtOffsetOf(face_landmark_detection, std);
face_landmark_detection_obj_handlers.free_obj = php_face_landmark_detection_free;
// FaceRecognition class definition
//
INIT_CLASS_ENTRY(ce, "FaceRecognition", face_recognition_class_methods);
face_recognition_ce = zend_register_internal_class(&ce TSRMLS_CC);
face_recognition_ce->create_object = php_face_recognition_new;
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.free_obj = php_face_recognition_free;
/* If you have INI entries, uncomment these lines
REGISTER_INI_ENTRIES();
*/