现在的位置: 首页 > 综合 > 正文

OpenCV和PHP的人脸识别技术

2012年10月04日 ⁄ 综合 ⁄ 共 2006字 ⁄ 字号 评论关闭
Php代码  收藏代码
  1. OpenCV安装之前必须依赖的包:(请先安装好)  
  2. pkgconfig  
  3. libpng  
  4. zlib  
  5. libjpeg  
  6. libtiff  
  7. python  
  8.   
  9. [OpenCV安装] www.opencv.org.  
  10. tar xvzf OpenCV-1.0.0.tar.gz  
  11. cd opencv-1.0.0  
  12. ./configure  
  13. make  
  14. make install  
  15. make check (检查是否安装全部正确)  
  16.   
  17. [facedetect] http://www.xarg.org/download/facedetect-1.0.0.tar.gz  
  18. tar xzvf facedetect-1.0.0.tar.gz  
  19. cd facedetect-1.0.0  
  20. /usr/local/php/bin/phpize  
  21. ./configure --with-php-config=/usr/local/php/bin/php-config  
  22. make  
  23. make test  
  24. make install  
  25.   
  26. [ImageMagick] http://www.imagemagick.org/  
  27. tar jxvf ImageMagick-6.5.0-0.tar.bz2  
  28. cd ImageMagick-6.5.0-0  
  29. ./configure  
  30. make  
  31. make install  
  32.   
  33. [imagick] http://pecl.php.net/imagick  
  34. tar zxvf imagick-2.3.0b1.tgz  
  35. imagick-2.3.0b1  
  36. /usr/local/php/bin/phpize  
  37. ./configure --with-php-config=/usr/local/php/bin/php-config  
  38. make  
  39. make test  
  40. make install  
  41.   
  42.   
  43. [配置]  
  44. ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/  
  45. 看看有没有 facedetect.so 和 imagick.so  
  46. vi /usr/local/php/lib/php.ini  
  47. 在[PHP]模块下增加:  
  48. extension = facedetect.so  
  49. extension = imagick.so  
  50. 重启apache  
  51.   
  52.   
  53. [测试代码]  
  54.   
  55.   
  56. 从openCV源代码/data/haarcascades/里头取出所有xml文件放在php的执行目录下  
  57.   
  58.   
  59.   
  60.   
  61.   
  62. //------------------  
  63.   
  64.   
  65. // 监测有几个人脸  
  66.   
  67.   
  68. //------------------  
  69.   
  70.   
  71. //检查有多少个脸型  
  72.   
  73.   
  74. var_dump(face_count('party.jpeg', haarcascade_frontalface_alt.xml'));  
  75.   
  76.   
  77. //返回脸型在图片中的位置参数,多个则返回数组  
  78.   
  79.   
  80. $arr = face_detect('party.jpeg', haarcascade_frontalface_alt2.xml');  
  81.   
  82.   
  83. print_r($arr);  
  84.   
  85.   
  86.   
  87.   
  88.   
  89. //------------------  
  90.   
  91.   
  92. // 人脸扭曲  
  93.   
  94.   
  95. //------------------  
  96.   
  97.   
  98. <?php  
  99.   
  100.   
  101. if($_FILES){  
  102.   
  103.   
  104. $img = $_FILES['pic']['tmp_name'];  
  105.   
  106.   
  107. $arr = face_detect($img'haarcascade_frontalface_alt2.xml');  
  108.   
  109.   
  110. //$arr1 = face_detect($img, 'haarcascade_frontalface_alt_tree.xml');  
  111.   
  112.   
  113. if(is_array($arr1)) $all =array_merge($arr,$arr1);  
  114.   
  115.   
  116. else $all = $arr;  
  117.   
  118.   
  119. $im = new Imagick($img);  
  120.   
  121.   
  122. //$draw =new ImagickDraw();  
  123.   
  124.   
  125. //$borderColor = new ImagickPixel('red');  
  126.   
  127.   
  128. //$draw->setFillAlpha(0.0);  
  129.   
  130.   
  131. //$draw->setStrokeColor ($borderColor);  
  132.   
  133.   
  134. //$draw->setStrokeWidth (1);  
  135.   
  136.   
  137. if(is_array($all)){  
  138.   
  139.   
  140. foreach ($all 

抱歉!评论已关闭.