色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

基于OpenCV的PHP圖像人臉識(shí)別技術(shù)

openCV是一個(gè)開源的用C/C++開發(fā)的計(jì)算機(jī)圖形圖像庫,非常強(qiáng)大,研究資料很齊全。本文重點(diǎn)是介紹如何使用php來調(diào)用其中的局部的功能。人臉偵查技術(shù)只是openCV一個(gè)應(yīng)用分支。
1.安裝
從源代碼編譯成一個(gè)動(dòng)態(tài)的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會(huì)找不到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
編譯完之后會(huì)提示facedetect.so 文件所在的位置。
最后確認(rèn)在php.ini加入
extension=facedetect.so,重啟apache.
2.函數(shù)使用
phpinfo()里檢查是否有facedetect這個(gè)模塊。
從openCV源代碼/data/haarcascades/里頭取出所有xml文件放在php的執(zhí)行目錄下
//檢查有多少個(gè)臉型
var_dump(face_count(‘party.jpeg', haarcascade_frontalface_alt.xml'));
//返回臉型在圖片中的位置參數(shù),多個(gè)則返回?cái)?shù)組
$arr = face_detect(‘party.jpeg', haarcascade_frontalface_alt2.xml');
print_r($arr);
3.應(yīng)用
結(jié)合imagick可以將圖片做一下應(yīng)用。因?yàn)?face_detect只返回一個(gè)矩形參數(shù),包含x,y坐標(biāo)和w,h長寬參數(shù)。下面是我的一個(gè)應(yīng)用demo
復(fù)制代碼 代碼如下:
<?php
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{
?>
<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8″ />
<form method=“POST” enctype=“multipart/form-data”>
人臉識(shí)別試驗(yàn):只支持jpg,png<br>
上傳一張圖片 <input type=“file” name=“pic”>
<input type=“submit” value=“upload”>
</form>
<?
}
?>

參考資料:
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

php技術(shù)基于OpenCV的PHP圖像人臉識(shí)別技術(shù),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 曲松县| 龙海市| 灵宝市| 鹤山市| 深水埗区| 霍州市| 桂阳县| 和田县| 女性| 息烽县| 县级市| 临安市| 团风县| 天祝| 临沭县| 高台县| 承德县| 百色市| 仙游县| 禹州市| 洛隆县| 华坪县| 武胜县| 青龙| 永寿县| 安丘市| 安吉县| 达尔| 文成县| 蒲江县| 手机| 宜良县| 吉木乃县| 日照市| 江津市| 东乡族自治县| 宽甸| 宝山区| 望江县| 汾西县| 巨鹿县|