基于 HTML5 的人脸识别技术

阅读: 评论:0

基于 HTML5 的人脸识别技术

基于 HTML5 的人脸识别技术

绍一个网站,演示了通过 HTML5 + JavaScript 技术实现的人脸识别,目前仅适用于 Chrome浏览器,首先需要在地址栏输入 about:flags ,然后找到“启用 MediaStream” 这一项,点击“启用” 后重启 Chrome 浏览器

然后打开下面地址:

/

当你摇头晃脑的时候,那副眼镜会跟着移动并帮你戴上眼镜。

你可以查看网页源码来了解具体的实现细节。

———————————–我是分界线———————————————

这是一篇国外的文章,介绍如何通过 WebRTC、OpenCV 和 WebSocket 技术实现在 Web 浏览器上的人脸识别,架构在 Jetty 之上。

实现的效果包括:

还能识别眼睛

人脸识别的核心代码:

页面:

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

 

JavaScript Code 复制内容到剪贴板
  1. public class FaceDetection {  
  2.   
  3. private static final String CASCADE_FILE ="resources/haarcascade_l";  
  4.   
  5. private int minsize >.html<= 20;  
  6. private int group = 0;  
  7. private double s>.html<cale = 1.1;  
  8.   
  9. /** 
  10. * Based on >.html<FaceDetection example from JavaCV. 
  11. */  
  12. public byte[] convert(byte[] imageData) throws IOException {  
  13. // create image from supplied bytearray  
  14. IplImage originalImage = cvDecodeImage(cvMat(1, imageData.length,CV_8UC1, newBytePointer(imageData)));  
  15.   
  16. // Convert to grayscale>.html< for recognition  
  17. IplImage grayImage = ate(originalImage.width(), originalImage.height(), IPL_DEPTH_8U, 1);  
  18. cvCvtColor(>.html<originalImage, grayImage, CV_BGR2GRAY);  
  19.   
  20. // storage is needed to store information during detection  
  21. CvMemStorage storage = ate();  
  22.   
  23. // Configuration to use in analysis  
  24. CvHaarClassifierCascade cascade = newCvHaarClassifierCascade(cvLoad(CASCADE_FILE));  
  25.   
  26. // We detect the>.html< faces.  
  27. CvSeq faces = cvHaarDetectObjects(grayImage, cascade, storage, scale, group, minsize);  
  28.   
  29. // We iterate over the discovered faces and draw yellow rectangles around them.  
  30. for (int i = 0; i < al(); i++) {  
  31. CvRect r = >.html<new CvRect(cvGetSeqElem(faces, i));  
  32. cvRectangle(originalImage, cvPoint(r.x(), r.y()),  
  33. cvPoint(r.x() + r.width(), r.y() + r.height()),  
  34. CvScalar.YELLOW, 1, CV_AA, 0);  
  35. }  
  36.   
  37. // convert the resulting image back to an array  
  38. ByteArrayOutputStream bout = new ByteArrayOutputStream();  
  39. BufferedImage imgb = BufferedImage();  
  40. ImageIO.write(imgb, "png", bout);  
  41. return ByteArray();  
  42. }  
  43. }  

详细的实现细节请阅读英文原文:

本文发布于:2024-02-04 22:47:17,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170718120760416.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:的人   技术
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23