基于HTML5的人脸识别技术

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

然后打开下面地址:

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

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

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

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

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

实现的效果包括:

Face Detection result

还能识别眼睛

Eye Detection result

人脸识别的核心代码:

页面:

XML/HTML Code复制内容到剪贴板
  1. <div> 
  2. <videoidvideoid="live"width="320"height="240" autoplay style="display: inline;"></video> 
  3. <canvaswidthcanvaswidth="320"id="canvas"height="240"style="display: inline;"></canvas> 
  4. </div> 
  5. <scripttypescripttype="text/javascript"> 
  6. var video = $("#live").get()[0];   
  7. var canvas = $("#canvas");   
  8. var ctx = canvas.get()[0].getContext('2d');   
  9. navigator.webkitGetUserMedia("video",   
  10. function(stream) {   
  11. video.src = webkitURL.createObjectURL(stream);   
  12. },   
  13. function(err) {   
  14. console.log("Unable to get video stream!")   
  15. }   
  16. )   
  17. timer = setInterval(   
  18. function () {   
  19. ctx.drawImage(video, 0, 0, 320, 240);   
  20. }, 250);   
  21. </script> 
JavaScript Code复制内容到剪贴板
  1. publicclass FaceDetection {   
  2. privatestaticfinal String CASCADE_FILE ="resources/haarcascade_frontalface_alt.xml";   
  3. privateint minsize = 20;   
  4. privateint group = 0;   
  5. privatedouble scale = 1.1;   
  6. /**  
  7. * Based on FaceDetection example from JavaCV.  
  8. */ 
  9. publicbyte[] convert(byte[] imageData) throws IOException {   
  10. // create image from supplied bytearray 
  11. IplImage originalImage = cvDecodeImage(cvMat(1, imageData.length,CV_8UC1, newBytePointer(imageData)));   
  12. // Convert to grayscale for recognition 
  13. IplImage grayImage = IplImage.create(originalImage.width(), originalImage.height(), IPL_DEPTH_8U, 1);   
  14. cvCvtColor(originalImage, grayImage, CV_BGR2GRAY);   
  15. // storage is needed to store information during detection 
  16. CvMemStorage storage = CvMemStorage.create();   
  17. // Configuration to use in analysis 
  18. CvHaarClassifierCascade cascade = newCvHaarClassifierCascade(cvLoad(CASCADE_FILE));   
  19. // We detect the faces. 
  20. CvSeq faces = cvHaarDetectObjects(grayImage, cascade, storage, scale, group, minsize);   
  21. // We iterate over the discovered faces and draw yellow rectangles around them. 
  22. for (int i = 0; i < faces.total(); i++) {   
  23. CvRect r = new CvRect(cvGetSeqElem(faces, i));   
  24. cvRectangle(originalImage, cvPoint(r.x(), r.y()),   
  25. cvPoint(r.x() + r.width(), r.y() + r.height()),   
  26. CvScalar.YELLOW, 1, CV_AA, 0);   
  27. }   
  28. // convert the resulting image back to an array 
  29. ByteArrayOutputStream bout = new ByteArrayOutputStream();   
  30. BufferedImage imgb = originalImage.getBufferedImage();   
  31. ImageIO.write(imgb, "png", bout);   
  32. return bout.toByteArray();   
  33. }   
  34. }   

原文链接:http://www.html5china.com/course/20120528_3742.html

责任编辑:陈四芳 来源: html5中文网
相关推荐

2012-04-28 14:01:17

HTML5

2021-10-13 15:15:22

人工智能AI人脸识别

2021-09-07 09:01:07

人脸识别人工智能数据

2021-08-13 10:01:19

人脸识别人工智能数据

2017-03-20 08:58:02

Python人脸识别AI

2020-11-18 09:43:29

人脸识别AI人工智能

2022-02-15 13:00:29

人工智能人脸识别机器学习

2011-08-01 16:43:51

ibmdwHTML5Dojo

2011-09-08 09:38:46

HTML5 WidgeDojo

2020-12-23 08:29:08

人脸识别AI人工智能

2017-07-24 15:06:02

代码人脸识别实践

2019-11-25 13:44:02

人脸识别AI人工智能

2021-08-06 09:30:34

人工智能AI人脸识别

2009-10-12 08:52:31

HTML5标准

2012-10-09 11:02:11

IBMdw

2021-02-03 14:43:40

人工智能人脸识别

2015-07-06 09:57:04

HTML5CSS框架BootFlat

2012-04-01 10:02:00

HTML5

2022-06-16 21:01:32

人脸识别人工智能生物识别

2021-04-12 14:40:50

人脸识别面部识别人工智能
点赞
收藏

51CTO技术栈公众号