OpenCV和PHP的人脸识别技术
OpenCV安装之前必须依赖的包:(请先安装好) pkgconfig libpng zlib libjpeg libtiff python [OpenCV安装] www.opencv.org. tar xvzf OpenCV-1.0.0.tar.gz cd opencv-1.0.0 ./configure make make install make check (检查是否安装全部正确) [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 /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make make test make install [ImageMagick] http://www.imagemagick.org/ tar jxvf ImageMagick-6.5.0-0.tar.bz2 cd ImageMagick-6.5.0-0 ./configure make make install [imagick] http://pecl.php.net/imagick tar zxvf imagick-2.3.0b1.tgz imagick-2.3.0b1 /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make make test make install [配置] ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/ 看看有没有 facedetect.so 和 imagick.so vi /usr/local/php/lib/php.ini 在[PHP]模块下增加: extension = facedetect.so extension = imagick.so 重启apache [测试代码] 从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); //------------------ // 人脸扭曲 //------------------ 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{ ?> } ?> //------------------ // 人脸识别 //------------------ $v){ $tmp_name_new = $tmp_name."_".$k; $x = $v['x']; $y = $v['y']; $w = $v['w']; $h = $v['h']; $dst_pic = "./".$tmp_name_new.$fix_pic; // echo $src_pic."
"; // echo $dst_pic."
"; $cmd = "/usr/local/bin/convert -crop ".$w."x".$h."+".$x."+".$y." ".$src_pic." ".$dst_pic; // echo $cmd."
"; echo `$cmd`; $pic_src[] = "./".$tmp_name.$fix_pic; $pic_dst[] = "./".$tmp_name_new.$fix_pic; } } foreach($pic_src as $key => $value) { echo " =>
"; } } ?>
登录后复制
?
?
目前,还为测试,等应用后,再公布实验结果~~
?
?
1 楼 悠悠晃晃 2011-03-21
facedetect在Windows服务器下如何安装啊,貌似没找到,你有吗?
2 楼 purpen 2011-03-26
悠悠晃晃 写道
facedetect在Windows服务器下如何安装啊,貌似没找到,你有吗?
没有,没在windows下测试。
没有,没在windows下测试。
09-06 07:03