php-facedetect_1.1.0+git20170801/0000755000175000017500000000000013140033675015725 5ustar mathieumathieuphp-facedetect_1.1.0+git20170801/facedetect.c0000644000175000017500000001146513140033675020167 0ustar mathieumathieu/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | This source file is subject to BSD 3-Clause license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://opensource.org/licenses/BSD-3-Clause. | | If you did not receive a copy of the BSD license and are unable to | | obtain it through the world-wide-web, please send a note to | | robert@xarg.org so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Robert Eisele | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "ext/standard/info.h" #include "php_facedetect.h" #include "opencv2/core/core_c.h" #include "opencv2/imgproc/imgproc_c.h" #include "opencv2/photo/photo_c.h" #include "opencv2/objdetect/objdetect_c.h" #include "opencv2/core/version.hpp" /* {{{ facedetect_functions[] * * Every user visible function must have an entry in facedetect_functions[]. */ static zend_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(); } /* }}} */ IplImage* cvLoadImage(char *file, int number); static void php_facedetect(INTERNAL_FUNCTION_PARAMETERS, int return_type) { char *file, *casc; long flen, clen; #ifdef ZEND_ENGINE_3 zval array; #else zval *array; #endif zval *pArray; 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(); } if(access(file, R_OK) == -1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image file is missing or could not be read.\n"); RETURN_FALSE; } img = cvLoadImage(file, 1); if(!img) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image could not be loaded.\n"); RETURN_FALSE; } if(access(casc, R_OK) == -1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Haar-cascade file is missing or could not be read.\n"); RETURN_FALSE; } cascade = (CvHaarClassifierCascade*)cvLoad(casc, 0, 0, 0); if(!cascade) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Haar-cascade file could not be loaded.\n"); 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), cvSize(0, 0)); if(return_type) { array_init(return_value); if(faces && faces->total > 0) { int i; for(i = 0; i < faces->total; i++) { #ifdef ZEND_ENGINE_3 ZVAL_NEW_ARR(&array); pArray = &array; #else MAKE_STD_ZVAL(array); pArray = array; #endif array_init(pArray); rect = (CvRect *)cvGetSeqElem(faces, i); add_assoc_long(pArray, "x", rect->x); add_assoc_long(pArray, "y", rect->y); add_assoc_long(pArray, "w", rect->width); add_assoc_long(pArray, "h", rect->height); add_next_index_zval(return_value, pArray); } } } 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); } /* }}} */ php-facedetect_1.1.0+git20170801/config.w320000644000175000017500000000122213140033675017524 0ustar mathieumathieu// $Id$ // vim:ft=javascript ARG_WITH("facedetect", "for facedetect support", "no"); if (PHP_FACEDETECT == "yes") { if (CHECK_LIB("opencv_objdetect*.lib", "facedetect", PHP_FACEDETECT) && CHECK_LIB("opencv_core*.lib", "facedetect", PHP_FACEDETECT) && CHECK_LIB("opencv_imgproc*.lib", "facedetect", PHP_FACEDETECT) && CHECK_LIB("opencv_highgui*.lib", "facedetect", PHP_FACEDETECT) && CHECK_HEADER_ADD_INCLUDE("opencv2/core/core_c.h", "CFLAGS_FFACEDETECT")) { AC_DEFINE("HAVE_FACEDETECT", 1); EXTENSION("facedetect", "facedetect.c", true); } else { WARNING("facedetect not enabled, headers or libraries not found"); } } php-facedetect_1.1.0+git20170801/INSTALL0000644000175000017500000000147513140033675016765 0ustar mathieumathieuInstalling 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 installphp-facedetect_1.1.0+git20170801/CREDITS0000644000175000017500000000005113140033675016741 0ustar mathieumathieuFacedetect Robert Eisele www.xarg.orgphp-facedetect_1.1.0+git20170801/README.md0000644000175000017500000000013513140033675017203 0ustar mathieumathieu# PHP-Facedetect A simple OpenCV wrapper for PHP to detect faces on images OpenCV 3 Support php-facedetect_1.1.0+git20170801/config.m40000644000175000017500000000155013140033675017435 0ustar mathieumathieuPHP_ARG_WITH(facedetect, for facedetect support, [ --with-facedetect Enable facedetect support]) if test "$PHP_FACEDETECT" != "no"; then AC_PATH_PROG(PKG_CONFIG, pkg-config, no) AC_MSG_CHECKING(for opencv) if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists opencv; then CV_INCLUDE=`$PKG_CONFIG opencv --variable=includedir_new` CV_LIBRARY=`$PKG_CONFIG opencv --libs` CV_VERSION=`$PKG_CONFIG opencv --modversion` if $PKG_CONFIG opencv --atleast-version=2.2.0 ; then AC_MSG_RESULT($CV_VERSION) else AC_MSG_ERROR(opencv version is too old) fi PHP_EVAL_LIBLINE($CV_LIBRARY, FACEDETECT_SHARED_LIBADD) PHP_ADD_INCLUDE($CV_INCLUDE) else AC_MSG_ERROR(Please reinstall opencv) fi PHP_SUBST(FACEDETECT_SHARED_LIBADD) AC_DEFINE(HAVE_FACEDETECT, 1, [ ]) PHP_NEW_EXTENSION(facedetect, facedetect.c, $ext_shared) fi php-facedetect_1.1.0+git20170801/LICENSE0000644000175000017500000000273313140033675016737 0ustar mathieumathieuCopyright (c) 2009, Robert Eisele All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.php-facedetect_1.1.0+git20170801/php_facedetect.h0000644000175000017500000000251413140033675021036 0ustar mathieumathieu/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | This source file is subject to BSD 3-Clause license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://opensource.org/licenses/BSD-3-Clause. | | If you did not receive a copy of the BSD license and are unable to | | obtain it through the world-wide-web, please send a note to | | robert@xarg.org so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Robert Eisele | +----------------------------------------------------------------------+ */ #ifndef PHP_FACEDETECT_H #define PHP_FACEDETECT_H #define PHP_FACEDETECT_VERSION "1.1.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