码迷,mamicode.com
首页 > Web开发 > 详细

基于opencv的人脸检测的web应用

时间:2014-06-14 21:57:39      阅读:379      评论:0      收藏:0      [点我收藏+]

标签:des   style   class   blog   code   java   

参考资料

https://github.com/bsdnoobz/web-based-face-detect

http://opencv-code.com/projects/web-based-interface-for-face-detection-with-opencv/

http://www.cnblogs.com/findingsea/archive/2012/03/31/2427833.html

 

流程如下图

bubuko.com,布布扣

 

背景知识

php调用exe的返回

<html>
  <body>
      <?php
        system("F:\\xampp\\htdocs\\webcam2\\phptest.exe", $info);
        echo $info;
      ?>
  </body>
</html>

bubuko.com,布布扣

bubuko.com,布布扣

在线人脸检测

目录结构

│  face-detect.exe
│  haarcascade_frontalface_alt.xml
│  shutter.mp3
│  test.html
│  test.php
│  testphp.php
│  webcam.js
│  webcam.swf
│  
└─out

 test.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>JPEGCam Test Page</title>
    <meta name="generator" content="TextMate http://macromates.com/">
    <meta name="author" content="Joseph Huckaby">
    <!-- Date: 2008-03-15 -->
</head>
<body>
    <table><tr><td valign=top>
    <h1>JPEGCam Test Page</h1>
    <h3>Demonstrates a very simple, one-click capture &amp; upload implementation</h3>
    
    <!-- First, include the JPEGCam JavaScript Library -->
    <script type="text/javascript" src="webcam.js"></script>
    
    <!-- Configure a few settings -->
    <script language="JavaScript">
        webcam.set_api_url( test.php );
        webcam.set_quality( 90 ); // JPEG quality (1 - 100)
        webcam.set_shutter_sound( true ); // play shutter click sound
    </script>
    
    <!-- Next, write the movie to the page at 320x240 -->
    <script language="JavaScript">
        document.write( webcam.get_html(320, 240) );
    </script>
    
    <!-- Some buttons for controlling things -->
    <br/><form>
        <input type=button value="Configure..." onClick="webcam.configure()">
        &nbsp;&nbsp;
        <input type=button value="Take Snapshot" onClick="webcam.snap()">
    </form>
    <img id="resultimg"  src="" />
    
<script language="JavaScript">
        webcam.set_hook( onComplete, my_callback_function );
        function my_callback_function(response) {
            //  alert("sucess " + response);
            document.getElementById("resultimg").src=""+response;
                webcam.reset();
        }
</script>

</body>
</html>

test.php

<?php

/* JPEGCam Test Script */
/* Receives JPEG webcam submission and saves to local file. */
/* Make sure your directory has permission to write files as your web server user! */

$filename = date(‘YmdHis‘) . ‘.jpg‘;
$result = file_put_contents( $filename, file_get_contents(‘php://input‘) );
$cmd  = ‘F://xampp//htdocs//face//face-detect//face-detect.exe --input="‘.$filename.‘" --outdir=out"‘;
exec($cmd, $info);
foreach ($info as $i => $line)
	{
			if (preg_match(‘/\d+,\s*([^\s]+)\s+\((\d+)x(\d+)\)/i‘, $line, $m))

			{
			//	print  ‘http://‘.$_SERVER[‘HTTP_HOST‘].dirname($_SERVER[‘REQUEST_URI‘])."/".$m[1];
			//	echo   "<br>";
			//	echo $m[2];
			//	echo $m[3];
			}
	}
$url = ‘http://‘ . $_SERVER[‘HTTP_HOST‘] . dirname($_SERVER[‘REQUEST_URI‘]) . ‘/‘ . $filename;
print "$url\n";

 实验结果

bubuko.com,布布扣

out目录里就有检测的脸了

source code download

http://pan.baidu.com/share/link?shareid=4035488383&uk=792406754

修改人脸检测自带的php文件

<?php
    $file = ‘uploads/‘.date(‘YmdHis‘).‘.jpg‘;;
    file_put_contents("$file", file_get_contents("php://input"));
    $cmd  = ‘F://xampp//htdocs//face//face-detect//face-detect.exe --input="‘.$file.‘" --outdir=uploads"‘;
//    $cmd  = ‘F://xampp//htdocs//face//face-detect//face-detect.exe --input=uploads//1.jpg --outdir=uploads‘;
    //    $last = exec($cmd, &$out);
    $last = exec($cmd, $out);
    if (strpos($last, ‘Error:‘) === false)
    {
        $res = array(‘success‘ => true);
        foreach ($out as $i => $line)
        {
            if (preg_match(‘/\d+,\s*([^\s]+)\s+\((\d+)x(\d+)\)/i‘, $line, $m))
                $res[‘images‘][] = array(‘src‘ => $m[1], ‘width‘ => $m[2], ‘height‘ => $m[3]);
        }
    }
    else
        $res = array(‘success‘ => false, ‘msg‘ => $last);
    header(‘Content-Type: application/json‘);
    echo json_encode($res);

效果

bubuko.com,布布扣



基于opencv的人脸检测的web应用,布布扣,bubuko.com

基于opencv的人脸检测的web应用

标签:des   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/yuliyang/p/3786197.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!