./000075500000000000000000000000001143101434600112065ustar00rootroot00000000000000./CREDITS000064400000000000000000000000511143101434600122220ustar00rootroot00000000000000Facedetect Robert Eisele www.xarg.org./INSTALL000064400000000000000000000014751143101434600122460ustar00rootroot00000000000000Installing 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./config.m4000064400000000000000000000030651143101434600127210ustar00rootroot00000000000000PHP_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([opencv/cv.h], [], AC_MSG_ERROR('opencv/cv.h' header not found)) AC_CHECK_HEADER([opencv/cvver.h], [], AC_MSG_ERROR('opencv/cvver.h' header not found)) AC_CHECK_HEADER([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 ./facedetect.c000064400000000000000000000067261143101434600134540ustar00rootroot00000000000000/* +----------------------------------------------------------------------+ | 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 | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_facedetect.h" #include #include #include static function_entry facedetect_functions[] = { PHP_FE(face_detect, NULL) PHP_FE(face_count, NULL) {NULL, NULL, NULL} }; 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_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); } PHP_FUNCTION(face_detect) { php_facedetect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } PHP_FUNCTION(face_count) { php_facedetect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } ./php_facedetect.h000064400000000000000000000025141143101434600143170ustar00rootroot00000000000000/* +----------------------------------------------------------------------+ | 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 | +----------------------------------------------------------------------+ */ #ifndef PHP_FACEDETECT_H #define PHP_FACEDETECT_H #define PHP_FACEDETECT_VERSION "1.0.0" #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