Home > Backend Development > PHP Tutorial > PHP image face recognition technology based on OpenCV_PHP tutorial

PHP image face recognition technology based on OpenCV_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:44:18
Original
1372 people have browsed it

openCV is an open source computer graphics library developed in C/C++. It is very powerful and has complete research materials. The focus of this article is to introduce how to use php to call local functions. Face detection technology is only an application branch of openCV.
1. Installation
Compile from source code into a dynamic so file.
1.1. Install OpenCV (OpenCV 1.0.0)
Download address: http://sourceforge.net/project/showfiles.php?group_id=22870&package_id=16948
#tar xvzf OpenCV-1.0.0. tar.gz
#cd opencv-1.0.0
#./configure
#make
#make install
#make check (check whether everything is installed correctly)
Tip: Don’t Specify the installation path, otherwise the OpenCV path will not be found when facedetect is compiled later.
1.2 Install facedetect
Download address http://www.xarg.org/download/facedetect-1.0.0.tar.gz
#tar xzvf facedetect-1.0.0.tar.gz
#cd facedetect-1.0.0
#phpize && ./configure && make && make install
After compilation, the location of the facedetect.so file will be prompted.
Finally make sure to add
extension=facedetect.so to php.ini and restart apache.
2. Function usage
Check whether there is facedetect module in phpinfo().
Extract all xml files from the openCV source code/data/haarcascades/ and place them in the php execution directory
//Check how many face shapes there are
var_dump(face_count('party.jpeg', haarcascade_frontalface_alt.xml '));
//Return the position parameters of the face shape in the picture, if there are multiple, return an array
$arr = face_detect('party.jpeg', haarcascade_frontalface_alt2.xml');
print_r($arr );
3. Application
Combined with imagick, you can apply the image. Because face_detect only returns a rectangle parameter, including x, y coordinates and w, h length and width parameters. Below is one of my application demos

Copy code The code is as follows:

if($_FILES ){
$img = $_FILES['pic']['tmp_name'];
$arr = face_detect($img, 'haarcascade_frontalface_alt2.xml');
//$arr1 = face_detect($ img, 'haarcascade_frontalface_alt_tree.xml');
if(is_array($arr1)) $all =array_merge($arr,$arr1);
else $all = $arr;
$im = new Imagick ($img);
//$draw =new ImagickDraw();
//$borderColor = new ImagickPixel('red');
//$draw->setFillAlpha(0.0);
//$draw->setStrokeColor ($borderColor);
//$draw->setStrokeWidth (1);
if(is_array($all)){
foreach ($all as $v){
$im_cl = $im->clone();
$im_cl->cropImage($v['w'],$v['h'],$v['x '],$v['y']);
$im_cl->swirlImage(60);
$im->compositeImage( $im_cl, Imagick::COMPOSITE_OVER , $v['x'] , $v['y'] );
//$draw->rectangle($v['x'],$v['y'],$v['x']+$v[' w'],$v['y']+$v['h']);
//$im->drawimage($draw);
}
}
header( "Content-Type: image/png" );
echo $im;
}else{
?>
http://www.xarg.org/2008/07/face-detection-with-php/
http ://www.opencv.org.cn/index.php/Homepage
http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/ index.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320585.htmlTechArticleopenCV is an open source computer graphics library developed in C/C++. It is very powerful and has complete research materials. The focus of this article is to introduce how to use php to call local functions. Face...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template