基于OpenCV的PHP图像人脸识别技术_PHP
openCV是一个开源的用C/C++开发的计算机图形图像库,非常强大,研究资料很齐全。本文重点是介绍如何使用php来调用其中的局部的功能。人脸侦查技术只是openCV一个应用分支。
1.安装
从源代码编译成一个动态的so文件。
1.1.安装 OpenCV (OpenCV 1.0.0)
下载地址: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 (检查是否安装全部正确)
提示: 不要指定安装路径,否则后面编译facedetect会找不到OpenCV的路径。
1.2 安装facedetect
下载地址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
编译完之后会提示facedetect.so 文件所在的位置。
最后确认在php.ini加入
extension=facedetect.so,重启apache.
2.函数使用
在phpinfo()里检查是否有facedetect这个模块。
从openCV源代码/data/haarcascades/里头取出所有xml文件放在php的执行目录下
//检查有多少个脸型
var_dump(face_count(‘party.jpeg', haarcascade_frontalface_alt.xml'));
//返回脸型在图片中的位置参数,多个则返回数组
$arr = face_detect(‘party.jpeg', haarcascade_frontalface_alt2.xml');
print_r($arr);
3.应用
结合imagick可以将图片做一下应用。因为 face_detect只返回一个矩形参数,包含x,y坐标和w,h长宽参数。下面是我的一个应用demo
复制代码 代码如下:
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/首页
http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/index.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to do face recognition and face detection in C++? Introduction: Face recognition and face detection are important research directions in the field of computer vision. They are widely used in image processing, security monitoring and other fields. This article will introduce how to use C++ language for face recognition and face detection, and give corresponding code examples. 1. Face detection Face detection refers to the process of locating and identifying faces in a given image. OpenCV is a popular computer vision library that provides functions related to face detection. Below is a simple person

Use the pip command to easily install OpenCV tutorial, which requires specific code examples. OpenCV (OpenSource Computer Vision Library) is an open source computer vision library. It contains a large number of computer vision algorithms and functions, which can help developers quickly build image and video processing related applications. Before using OpenCV, we need to install it first. Fortunately, Python provides a powerful tool pip to manage third-party libraries

OpenCV is an open source library for computer vision and image processing, which is widely used in machine learning, image recognition, video processing and other fields. When developing using OpenCV, in order to better debug and run programs, many developers choose to use PyCharm, a powerful Python integrated development environment. This article will provide PyCharm users with an installation tutorial for OpenCV, with specific code examples. Step One: Install Python First, make sure you have Python installed

PHP study notes: Face recognition and image processing Preface: With the development of artificial intelligence technology, face recognition and image processing have become hot topics. In practical applications, face recognition and image processing are mostly used in security monitoring, face unlocking, card comparison, etc. As a commonly used server-side scripting language, PHP can also be used to implement functions related to face recognition and image processing. This article will take you through face recognition and image processing in PHP, with specific code examples. 1. Face recognition in PHP Face recognition is a

As an intelligent service software, DingTalk not only plays an important role in learning and work, but is also committed to improving user efficiency and solving problems through its powerful functions. With the continuous advancement of technology, facial recognition technology has gradually penetrated into our daily life and work. So how to use the DingTalk app for facial recognition entry? Below, the editor will bring you a detailed introduction. Users who want to know more about it can follow the pictures and text of this article! How to record faces on DingTalk? After opening the DingTalk software on your mobile phone, click "Workbench" at the bottom, then find "Attendance and Clock" and click to open. 2. Then click "Settings" on the lower right side of the attendance page to enter, and then click "My Settings" on the settings page to switch.

How to use Golang to perform face recognition and face fusion on pictures. Face recognition and face fusion are common tasks in the field of computer vision, and Golang, as an efficient and powerful programming language, can also play an important role in these tasks. This article will introduce how to use Golang to perform face recognition and face fusion on images, and provide relevant code examples. 1. Face recognition Face recognition refers to the technology of matching or identifying faces with known faces through facial features in images or videos. In Golang

1. We can ask Siri before going to bed: Whose phone is this? Siri will automatically help us disable face recognition. 2. If you don’t want to disable it, you can turn on Face ID and choose to turn on [Require gaze to enable Face ID]. In this way, the lock screen can only be opened when we are watching.

How to implement face recognition algorithm in C# Face recognition algorithm is an important research direction in the field of computer vision. It can be used to identify and verify faces, and is widely used in security monitoring, face payment, face unlocking and other fields. In this article, we will introduce how to use C# to implement the face recognition algorithm and provide specific code examples. The first step in implementing a face recognition algorithm is to obtain image data. In C#, we can use the EmguCV library (C# wrapper for OpenCV) to process images. First, we need to create the project
