Home Backend Development PHP Tutorial 基于OpenCV的PHP图像人脸识别技术_PHP

基于OpenCV的PHP图像人脸识别技术_PHP

Jun 01, 2016 pm 12:22 PM
opencv face recognition

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{
?>


人脸识别试验:只支持jpg,png

上传一张图片



}
?>

参考资料:
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

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to do face recognition and face detection in C++? How to do face recognition and face detection in C++? Aug 27, 2023 am 08:30 AM

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

Quickly install OpenCV study guide using pip package manager Quickly install OpenCV study guide using pip package manager Jan 18, 2024 am 09:55 AM

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 installation tutorial: a must-read for PyCharm users OpenCV installation tutorial: a must-read for PyCharm users Feb 22, 2024 pm 09:21 PM

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 PHP study notes: face recognition and image processing Oct 08, 2023 am 11:33 AM

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

How to enter DingTalk face recognition How to enter DingTalk face recognition Mar 05, 2024 am 08:46 AM

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 How to use Golang to perform face recognition and face fusion on pictures Aug 26, 2023 pm 05:52 PM

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

How to turn off face recognition on Apple phone_How to disable face recognition on Apple phone settings How to turn off face recognition on Apple phone_How to disable face recognition on Apple phone settings Mar 23, 2024 pm 08:20 PM

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# How to implement face recognition algorithm in C# Sep 19, 2023 am 08:57 AM

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

See all articles