- 好友
- 0
- 帖子
- 130227
- 積分
- 136402
- 最後登錄
- 2019-2-28
- 在線時間
- 0 小時
- 好友
- 0
- 帖子
- 130227
- 積分
- 136402
- 最後登錄
- 2019-2-28
- 在線時間
- 0 小時
|
使用 HTML5, javascript, webrtc, websockets, Jetty 和 OpenCV 实现基於 Web 的人脸识别这是一篇国外的文章,介绍如何通过 WebRTC、OpenCV 和 WebSocket 技术实现在 Web 浏览器上的人脸识别,架構在 Jetty 之上。实现的效果包括: 人脸识别的核心代码:页面:01020304
0506後臺:01public class FaceDetection {0203private static final String CASCADE_FILE = resources/haarcascade_frontalface_alt.xml;0405private int minsize = 20;06private int group = 0;07private double scale = 1.1;0809/**10* Based on FaceDetection example from JavaCV.11*/12public byte[] convert(byte[] imageData) throws IOException {13// create image from supplied bytearray14IplImage originalImage = cvDecodeImage(cvMat(1, imageData.length,CV_8UC1, new BytePointer(imageData)));1516// Convert to grayscale for recognition17IplImage grayImage = IplImage.create(originalImage.width(), originalImage.height(), IPL_DEPTH_8U, 1);18cvCvtColor(originalImage, grayImage, CV_BGR2GRAY);1920// storage is needed to store information during detection21CvMemStorage storage = CvMemStorage.create();2223// Configuration to use in analysis24CvHaarClassifierCascade cascade = new CvHaarClassifierCascade(cvLoad(CASCADE_FILE));2526// We detect the faces.27CvSeq faces = cvHaarDetectObjects(grayImage, cascade, storage, scale, group, minsize);2829// We iterate over the discovered faces and draw yellow rectangles around them.30for (int i = 0; i < faces.total(); i++) {31CvRect r = new CvRect(cvGetSeqElem(faces, i));32cvRectangle(originalImage, cvPoint(r.x(), r.y()),33cvPoint(r.x() + r.width(), r.y() + r.height()),34CvScalar.YELLOW, 1, CV_AA, 0);35}3637// convert the resulting image back to an array38ByteArrayOutputStream bout = new ByteArrayOutputStream();39BufferedImage imgb = originalImage.getBufferedImage();40ImageIO.write(imgb, png, bout);41return bout.toByteArray();42}43}详细的实现细节请阅读英文原文:http://www.smartjava.org/content ... ty-and-javacvopencv |
|