With OpenCV it is possible to find structures on images. The library is shipped with training files to detect faces from different perspectives on images. To access the library and detect faces via PHP I wrote a wrapper.
Overview
This extension provides a PHP implementation of the OpenCV library. The extension offers two new functions. In princible, they differ only by their return value. The first returns only the number of faces found on the given image and the other an associative array of their coordinates.
<?php
var_dump(face_count('party.jpeg', 'cascade.xml'));
var_dump(face_detect('party.jpeg', 'cascade.xml'));
?>
Installation
Installing with `pecl` command-line utility
- Install OpenCV (OpenCV 2.3.1)
- Execute command "pecl install facedetect"
- Make sure you have extension=facedetect.so in your php.ini
Installing from sources
- Install OpenCV (OpenCV 2.3.1)
- Download facedetect source package
- Unpack facedetect source package
- Go to facedetect folder and type "phpize && ./configure && make && make install"
- Make sure you have extension=facedetect.so in your php.ini
Compiling Facedtect into PHP
- Install OpenCV (OpenCV 2.3.1)
- Download facedetect source package
- Unpack facedetect source package to $PHP_SOURCE_DIR/ext/facedetect
- In php source root directory run commands: "rm configure && ./buildconf --force"
- Configure PHP with command "./configure --with-facedetect"
- Run make && make install
Installation note
You should know, that OpenCV needs the following libraries and programs:
- pkgconfig
- libpng
- zlib
- libjpeg
- libtiff
- python
If you use Debian you can install the needed packages by run the following command:
# apt-get install pkg-config python libjpeg62-dev libpng12-dev libtiff4-dev
For details on how install OpenCV on Linux check out the OpenCV install guide