first commit
Esse commit está contido em:
@@ -0,0 +1,4 @@
|
|||||||
|
Facedetect
|
||||||
|
Robert Eisele
|
||||||
|
|
||||||
|
www.xarg.org
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
Installing with `pecl` command-line utility
|
||||||
|
|
||||||
|
1. Install OpenCV libraries (at least version 1.0.0)
|
||||||
|
2. Execute command "pecl install facedetect"
|
||||||
|
3. Make sure you have extension=facedetect.so in your php.ini
|
||||||
|
|
||||||
|
|
||||||
|
Installing from sources
|
||||||
|
|
||||||
|
1. Install OpenCV libraries (at least version 1.0.0)
|
||||||
|
2. Unpack facedetect source package
|
||||||
|
3. Go to facedetect folder and type "phpize && ./configure && make && make install"
|
||||||
|
4. Make sure you have extension=facedetect.so in your php.ini
|
||||||
|
|
||||||
|
|
||||||
|
Compiling Facedetect into PHP
|
||||||
|
|
||||||
|
1. Install OpenCV libraries (at least version 1.0.0)
|
||||||
|
2. Unpack facedetect source package to $PHP_SOURCE_DIR/ext/facedetect
|
||||||
|
3. In php source root directory run commands: "rm configure && ./buildconf --force"
|
||||||
|
4. Configure PHP with command "./configure --with-facedetect"
|
||||||
|
5. Run make && make install
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
PHP_ARG_WITH(facedetect, for facedetect support, [ --with-facedetect Enable facedetect support])
|
||||||
|
|
||||||
|
if test "$PHP_FACEDETECT" != "no"; then
|
||||||
|
SEARCH_PATH="/usr/local /usr"
|
||||||
|
SEARCH_FOR="/include/opencv/cv.h"
|
||||||
|
|
||||||
|
if test -r $PHP_FACEDETECT/$SEARCH_FOR; then
|
||||||
|
FACEDETECT_DIR=$PHP_FACEDETECT
|
||||||
|
else
|
||||||
|
AC_MSG_CHECKING([for facedetect in default path])
|
||||||
|
for i in $SEARCH_PATH ; do
|
||||||
|
if test -r $i/$SEARCH_FOR; then
|
||||||
|
FACEDETECT_DIR=$i
|
||||||
|
AC_MSG_RESULT(found in $i)
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "$FACEDETECT_DIR"; then
|
||||||
|
AC_MSG_RESULT([not found])
|
||||||
|
AC_MSG_ERROR([Please reinstall the OpenCV distribution])
|
||||||
|
fi
|
||||||
|
|
||||||
|
PHP_ADD_INCLUDE($FACEDETECT_DIR/include)
|
||||||
|
|
||||||
|
AC_CHECK_HEADER([$FACEDETECT_DIR/include/opencv/cv.h], [], AC_MSG_ERROR('opencv/cv.h' header not found))
|
||||||
|
AC_CHECK_HEADER([$FACEDETECT_DIR/include/opencv/cvver.h], [], AC_MSG_ERROR('opencv/cvver.h' header not found))
|
||||||
|
AC_CHECK_HEADER([$FACEDETECT_DIR/include/opencv/highgui.h], [], AC_MSG_ERROR('opencv/highgui.h' header not found))
|
||||||
|
|
||||||
|
PHP_CHECK_LIBRARY(cv, cvLoad,
|
||||||
|
[
|
||||||
|
PHP_ADD_LIBRARY_WITH_PATH(cv, $FACEDETECT_DIR/lib, FACEDETECT_SHARED_LIBADD)
|
||||||
|
PHP_ADD_LIBRARY_WITH_PATH(cvaux, $FACEDETECT_DIR/lib, FACEDETECT_SHARED_LIBADD)
|
||||||
|
PHP_ADD_LIBRARY_WITH_PATH(highgui, $FACEDETECT_DIR/lib, FACEDETECT_SHARED_LIBADD)
|
||||||
|
PHP_ADD_LIBRARY_WITH_PATH(cxcore, $FACEDETECT_DIR/lib, FACEDETECT_SHARED_LIBADD)
|
||||||
|
AC_DEFINE(HAVE_FACEDETECT, 1, [ ])
|
||||||
|
],[
|
||||||
|
AC_MSG_ERROR([wrong OpenCV version or OpenCV not found])
|
||||||
|
],[
|
||||||
|
])
|
||||||
|
|
||||||
|
PHP_SUBST(FACEDETECT_SHARED_LIBADD)
|
||||||
|
AC_DEFINE(HAVE_FACEDETECT, 1, [ ])
|
||||||
|
PHP_NEW_EXTENSION(facedetect, facedetect.c, $ext_shared)
|
||||||
|
fi
|
||||||
|
|
||||||
+153
@@ -0,0 +1,153 @@
|
|||||||
|
/*
|
||||||
|
+----------------------------------------------------------------------+
|
||||||
|
| PHP Version 5 |
|
||||||
|
+----------------------------------------------------------------------+
|
||||||
|
| This source file is subject to version 3.0 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_0.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: Robert Eisele <robert@xarg.org> |
|
||||||
|
+----------------------------------------------------------------------+
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
#include "php.h"
|
||||||
|
#include "php_facedetect.h"
|
||||||
|
|
||||||
|
#include <opencv/cv.h>
|
||||||
|
#include <opencv/cvver.h>
|
||||||
|
#include <opencv/highgui.h>
|
||||||
|
|
||||||
|
/* {{{ facedetect_functions[]
|
||||||
|
*
|
||||||
|
* Every user visible function must have an entry in facedetect_functions[].
|
||||||
|
*/
|
||||||
|
static function_entry facedetect_functions[] = {
|
||||||
|
PHP_FE(face_detect, NULL)
|
||||||
|
PHP_FE(face_count, NULL)
|
||||||
|
{NULL, NULL, NULL}
|
||||||
|
};
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
/* {{{ facedetect_module_entry
|
||||||
|
*/
|
||||||
|
zend_module_entry facedetect_module_entry = {
|
||||||
|
#if ZEND_MODULE_API_NO >= 20010901
|
||||||
|
STANDARD_MODULE_HEADER,
|
||||||
|
#endif
|
||||||
|
PHP_FACEDETECT_EXTNAME,
|
||||||
|
facedetect_functions,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
PHP_MINFO(facedetect),
|
||||||
|
#if ZEND_MODULE_API_NO >= 20010901
|
||||||
|
PHP_FACEDETECT_VERSION,
|
||||||
|
#endif
|
||||||
|
STANDARD_MODULE_PROPERTIES
|
||||||
|
};
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
#ifdef COMPILE_DL_FACEDETECT
|
||||||
|
ZEND_GET_MODULE(facedetect)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* {{{ PHP_MINIT_FUNCTION
|
||||||
|
*/
|
||||||
|
PHP_MINFO_FUNCTION(facedetect)
|
||||||
|
{
|
||||||
|
php_info_print_table_start();
|
||||||
|
php_info_print_table_row(2, "facedetect support", "enabled");
|
||||||
|
php_info_print_table_row(2, "facedetect version", PHP_FACEDETECT_VERSION);
|
||||||
|
php_info_print_table_row(2, "OpenCV version", CV_VERSION);
|
||||||
|
php_info_print_table_end();
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
static void php_facedetect(INTERNAL_FUNCTION_PARAMETERS, int return_type)
|
||||||
|
{
|
||||||
|
char *file, *casc;
|
||||||
|
long flen, clen;
|
||||||
|
|
||||||
|
zval *array;
|
||||||
|
|
||||||
|
CvHaarClassifierCascade* cascade;
|
||||||
|
IplImage *img, *gray;
|
||||||
|
CvMemStorage *storage;
|
||||||
|
CvSeq *faces;
|
||||||
|
CvRect *rect;
|
||||||
|
|
||||||
|
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &file, &flen, &casc, &clen) == FAILURE) {
|
||||||
|
RETURN_NULL();
|
||||||
|
}
|
||||||
|
|
||||||
|
img = cvLoadImage(file, 1);
|
||||||
|
if(!img) {
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
cascade = (CvHaarClassifierCascade*)cvLoad(casc, 0, 0, 0);
|
||||||
|
if(!cascade) {
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gray = cvCreateImage(cvSize(img->width, img->height), 8, 1);
|
||||||
|
cvCvtColor(img, gray, CV_BGR2GRAY);
|
||||||
|
cvEqualizeHist(gray, gray);
|
||||||
|
|
||||||
|
storage = cvCreateMemStorage(0);
|
||||||
|
|
||||||
|
faces = cvHaarDetectObjects(gray, cascade, storage, 1.1, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(0, 0));
|
||||||
|
|
||||||
|
if(return_type) {
|
||||||
|
|
||||||
|
array_init(return_value);
|
||||||
|
|
||||||
|
if(faces && faces->total > 0) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < faces->total; i++) {
|
||||||
|
MAKE_STD_ZVAL(array);
|
||||||
|
array_init(array);
|
||||||
|
|
||||||
|
rect = (CvRect *)cvGetSeqElem(faces, i);
|
||||||
|
|
||||||
|
add_assoc_long(array, "x", rect->x);
|
||||||
|
add_assoc_long(array, "y", rect->y);
|
||||||
|
add_assoc_long(array, "w", rect->width);
|
||||||
|
add_assoc_long(array, "h", rect->height);
|
||||||
|
|
||||||
|
add_next_index_zval(return_value, array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
RETVAL_LONG(faces ? faces->total : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
cvReleaseMemStorage(&storage);
|
||||||
|
cvReleaseImage(&gray);
|
||||||
|
cvReleaseImage(&img);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* {{{ proto array face_detect(string picture_path, string cascade_file)
|
||||||
|
Finds coordinates of faces (or in gernal "objects") on the given picture */
|
||||||
|
PHP_FUNCTION(face_detect)
|
||||||
|
{
|
||||||
|
php_facedetect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
/* {{{ proto int face_count(string picture_path, string cascade_file)
|
||||||
|
Finds number of faces (or in gernal "objects") on the given picture*/
|
||||||
|
PHP_FUNCTION(face_count)
|
||||||
|
{
|
||||||
|
php_facedetect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
+----------------------------------------------------------------------+
|
||||||
|
| PHP Version 5 |
|
||||||
|
+----------------------------------------------------------------------+
|
||||||
|
| This source file is subject to version 3.0 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_0.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: Robert Eisele <robert@xarg.org> |
|
||||||
|
+----------------------------------------------------------------------+
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PHP_FACEDETECT_H
|
||||||
|
#define PHP_FACEDETECT_H
|
||||||
|
|
||||||
|
#define PHP_FACEDETECT_VERSION "1.0.1"
|
||||||
|
#define PHP_FACEDETECT_EXTNAME "facedetect"
|
||||||
|
|
||||||
|
#ifdef ZTS
|
||||||
|
# include "TSRM.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
PHP_MINFO_FUNCTION(facedetect);
|
||||||
|
|
||||||
|
PHP_FUNCTION(face_detect);
|
||||||
|
PHP_FUNCTION(face_count);
|
||||||
|
|
||||||
|
extern zend_module_entry facedetect_module_entry;
|
||||||
|
#define phpext_facedetect_ptr &facedetect_module_entry
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
Referência em uma Nova Issue
Bloquear um usuário