基於opencv的臉部偵測的web應用

來源:互聯網
上載者:User

標籤: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

 

流程如

 

背景知識php調用exe的返回
<html>  <body>      <?php        system("F:\\xampp\\htdocs\\webcam2\\phptest.exe", $info);        echo $info;      ?>  </body></html>

線上臉部偵測
  • 使用web網路攝影機
  • web-based-face-detect

目錄結構

│  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";
 實驗結果

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);

效果



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.