萬盛學電腦網

 萬盛學電腦網 >> 網頁制作 >> Html5 >> 基於HTML5 的人臉識別技術核心代碼

基於HTML5 的人臉識別技術核心代碼

  紹一個網站,演示了通過 HTML5 + JavaScript 技術實現的人臉識別,目前僅適用於 Chrome浏覽器,首先需要在地址欄輸入 about:flags ,然後找到“啟用 MediaStream” 這一項,點擊“啟用” 後重啟 Chrome 浏覽器

基於HTML5 的人臉識別技術核心代碼 三聯

  然後打開下面地址:

  http://neave.com/webcam/html5/face/

  當你搖頭晃腦的時候,那副眼鏡會跟著移動並幫你戴上眼鏡。

  你可以查看網頁源碼來了解具體的實現細節。

  ———————————–我是分界線———————————————

  這是一篇國外的文章,介紹如何通過 WebRTC、OpenCV 和 WebSocket 技術實現在 Web 浏覽器上的人臉識別,架構在 Jetty 之上。

  實現的效果包括:

Face Detection result

  還能識別眼睛

 

Eye Detection result

 

人臉識別的核心代碼:

頁面:

XML/HTML Code復制內容到剪貼板
  1. <div>  
  2. <video id="live" width="320" height="240" autoplay style="display: inline;"></video>  
  3. <canvas width="320" id="canvas" height="240" style="display: inline;"></canvas>  
  4. </div>  
  5.   
  6. <script type="text/javascript">  
  7. var video = $("#live").get()[0];  
  8. var canvas = $("#canvas");  
  9. var ctx = canvas.get()[0].getContext('2d');  
  10.   
  11. navigator.webkitGetUserMedia("video",  
  12. function(stream) {  
  13. video.src = webkitURL.createObjectURL(stream);  
  14. },  
  15. function(err) {  
  16. console.log("Unable to get video stream!")  
  17. }  
  18. )  
  19.   
  20. timer = setInterval(  
  21. function () {  
  22. ctx.drawImage(video, 0, 0, 320, 240);  
  23. }, 250);  
  24. </script>  

 

JavaScript Code復制內容到剪貼板
  1. public class FaceDetection {  
  2.   
  3. private static final String CASCADE_FILE ="resources/haarcascade_frontalface_alt.xml";  
  4.   
  5. private int minsize = 20;  
copyright © 萬盛學電腦網 all rights reserved