OPENCV-based human face recognition technology for PHP images _php tutorial

Source: Internet
Author: User
OpenCV is an open source computer graphics and image Library developed in C/s + +, very powerful and complete in research materials. The focus of this article is to describe how to use PHP to invoke local functionality. Face detection technology is just a branch of OPENCV application.
1. Installation
Compiled from the source code into a dynamic so file.
1.1. Installing 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 (checks whether the installation is all correct)
Tip: Do not specify the installation path, or you will not find the path to the OPENCV after compiling facedetect.
1.2 Installing 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 compiling, you will be prompted where the facedetect.so file is located.
Finally confirm to join in php.ini
extension=facedetect.so, restart Apache.
2. Function usage
Check for Facedetect this module in Phpinfo ().
Remove all XML files from OpenCV source code/data/haarcascades/in PHP's execution directory
Check how many face shapes you have.
Var_dump (Face_count (' Party.jpeg ', Haarcascade_frontalface_alt.xml '));
Returns the position parameter of the face shape in the picture, multiple returns the array
$arr = Face_detect (' party.jpeg ', Haarcascade_frontalface_alt2.xml ');
Print_r ($arr);
3. Application
The combination of Imagick can be used to make pictures. Because Face_detect only returns a rectangle parameter, it contains the x, y coordinates, and the w,h length-width parameter. Here is one of my application demo
Copy CodeThe code is as follows:
if ($_files) {
$img = $_files[' pic ' [' tmp_name '];
$arr = Face_detect ($img, ' haarcascade_frontalface_alt2.xml ');
$arr 1 = face_detect ($img, ' haarcascade_frontalface_alt_tree.xml ');
if (Is_array ($arr 1)) $all =array_merge ($arr, $arr 1);
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{
?>


}
?>

Resources:
http://www.xarg.org/2008/07/face-detection-with-php/
http://www.opencv.org.cn/index.php/Home
Http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/index.html

http://www.bkjia.com/PHPjc/320585.html www.bkjia.com true http://www.bkjia.com/PHPjc/320585.html techarticle OpenCV is an open source computer graphics and image Library developed in C/s + +, very powerful and complete in research materials. The focus of this article is to describe how to use PHP to invoke local functionality. Human Face ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.