<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>影の域 &#187; C</title>
	<atom:link href="http://www.zfkun.com/index.php/category/code/c/feed" rel="self" type="application/rss+xml" />
	<link>http://www.zfkun.com</link>
	<description>关注web前端,追逐html5脚步,体会code人生</description>
	<lastBuildDate>Mon, 23 Apr 2012 15:09:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>基于OpenCV的PHP图像人脸识别技术</title>
		<link>http://www.zfkun.com/39.html</link>
		<comments>http://www.zfkun.com/39.html#comments</comments>
		<pubDate>Sat, 16 Jan 2010 15:22:35 +0000</pubDate>
		<dc:creator>影之迷惑</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[facedetect]]></category>
		<category><![CDATA[opencv]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[人脸识别]]></category>
		<category><![CDATA[扩展]]></category>

		<guid isPermaLink="false">http://www.zfkun.com/blog/?p=39</guid>
		<description><![CDATA[写了一个PHP扩展openCV，只封装了两个函数，叫face_detect和face_count。openCV是一个开源的用C/C++开发的计算机图形图像库，非常强大，研究资料很齐全。本文重点是介绍如何使用php来调用其中的局部的功能。人脸侦查技术只是openCV一个应用分支。 <a href="http://www.zfkun.com/39.html">阅读全文 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>写了一个PHP扩展openCV，只封装了两个函数，叫face_detect和face_count。openCV是一个开源的用C/C++开发的计算机图形图像库，非常强大，研究资料很齐全。本文重点是介绍如何使用php来调用其中的局部的功能。人脸侦查技术只是openCV一个应用分支。</p>
<p>1.安装<br />
从源代码编译成一个动态的so文件。</p>
<p>1.1.安装 OpenCV (OpenCV 1.0.0)<br />
下载地址:http://sourceforge.net/project/showfiles.php?group_id=22870&#038;package_id=16948</p>
<pre name="code" class="c">
#tar xvzf OpenCV-1.0.0.tar.gz
#cd opencv-1.0.0
#./configure
#make
#make install
#make check (检查是否安装全部正确)
</pre>
<p>提示： 不要指定安装路径，否则后面编译facedetect会找不到OpenCV的路径。</p>
<p>1.2 安装facedetect<br />
下载地址http://www.xarg.org/download/facedetect-1.0.0.tar.gz</p>
<pre name="code" class="c">
#tar xzvf facedetect-1.0.0.tar.gz
#cd facedetect-1.0.0
#phpize &#038;&#038; ./configure &#038;&#038; make &#038;&#038; make install
</pre>
<p>编译完之后会提示facedetect.so 文件所在的位置。</p>
<p>最后确认在php.ini加入<br />
extension=facedetect.so，重启apache.</p>
<p>2.函数使用<br />
在phpinfo()里检查是否有facedetect这个模块。<br />
从openCV源代码/data/haarcascades/里头取出所有xml文件放在php的执行目录下</p>
<pre name="code" class="php">
//检查有多少个脸型
var_dump(face_count('party.jpeg', haarcascade_frontalface_alt.xml'));
//返回脸型在图片中的位置参数，多个则返回数组
$arr = face_detect('party.jpeg', haarcascade_frontalface_alt2.xml');
print_r($arr);
</pre>
<p>3.应用<br />
结合imagick可以将图片做一下应用。因为 face_detect只返回一个矩形参数，包含x，y坐标和w，h长宽参数。下面是我的一个应用demo</p>
<pre name="code" class="php">
&lt;?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{
?&gt;
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8″ />
<form method="POST" enctype="multipart/form-data">
  人脸识别试验：只支持jpg,png
  上传一张图片
<input type="file" name="pic">
<input type="submit" value="upload">
  </form>

&lt;?
}
?&gt;
</pre>
<p>
参考资料:</p>
<p>http://www.xarg.org/2008/07/face-detection-with-php/</p>
<p>http://www.opencv.org.cn/index.php/首页</p>
<p>http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/index.html</p>

	标签：<a href="http://www.zfkun.com/tag/facedetect" title="facedetect" rel="tag">facedetect</a>, <a href="http://www.zfkun.com/tag/opencv" title="opencv" rel="tag">opencv</a>, <a href="http://www.zfkun.com/tag/php" title="PHP" rel="tag">PHP</a>, <a href="http://www.zfkun.com/tag/%e4%ba%ba%e8%84%b8%e8%af%86%e5%88%ab" title="人脸识别" rel="tag">人脸识别</a>, <a href="http://www.zfkun.com/tag/%e6%89%a9%e5%b1%95" title="扩展" rel="tag">扩展</a><br />

	<h4>相关推荐</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.zfkun.com/135.html" title="挑战 hax.tor.hu 申请带ssh的免费php+mysql空间 (2010 年 03 月 19 日)" data-comment="0">挑战 hax.tor.hu 申请带ssh的免费php+mysql空间</a></li>
	<li><a href="http://www.zfkun.com/223.html" title="动态生成windows快捷方式文件 (2011 年 04 月 02 日)" data-comment="0">动态生成windows快捷方式文件</a></li>
	<li><a href="http://www.zfkun.com/417.html" title="WordPress Rewrite SEO 之404方式折腾笔记 (2011 年 07 月 17 日)" data-comment="1">WordPress Rewrite SEO 之404方式折腾笔记</a></li>
	<li><a href="http://www.zfkun.com/102.html" title="Windows 下 Nginx + PHP5 的安装与配置 (2010 年 01 月 28 日)" data-comment="0">Windows 下 Nginx + PHP5 的安装与配置</a></li>
	<li><a href="http://www.zfkun.com/35.html" title="PHP CURL函数库 (2010 年 01 月 16 日)" data-comment="0">PHP CURL函数库</a></li>
	<li><a href="http://www.zfkun.com/95.html" title="Nginx 0.8.x + PHP 5.2.10（FastCGI）搭建胜过Apache十倍的Web服务器（第5版） (2010 年 01 月 28 日)" data-comment="0">Nginx 0.8.x + PHP 5.2.10（FastCGI）搭建胜过Apache十倍的Web服务器（第5版）</a></li>
	<li><a href="http://www.zfkun.com/21.html" title="iconv 方法使用 (2010 年 01 月 16 日)" data-comment="0">iconv 方法使用</a></li>
	<li><a href="http://www.zfkun.com/229.html" title="fastcgi_finish_request提速程序执行 (2011 年 04 月 13 日)" data-comment="3">fastcgi_finish_request提速程序执行</a></li>
	<li><a href="http://www.zfkun.com/33.html" title="domdocument::domdocument() expects at least 1 parameter解决办法 (2010 年 01 月 16 日)" data-comment="0">domdocument::domdocument() expects at least 1 parameter解决办法</a></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.zfkun.com/39.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

