您好,登錄后才能下訂單哦!
基于HTML5的人臉識(shí)別技術(shù)是怎樣的,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
然后打開(kāi)下面地址:
http://neave.com/webcam/html5/face/
當(dāng)你搖頭晃腦的時(shí)候,那副眼鏡會(huì)跟著移動(dòng)并幫你戴上眼鏡。
你可以查看網(wǎng)頁(yè)源碼來(lái)了解具體的實(shí)現(xiàn)細(xì)節(jié)。
———————————–我是分界線———————————————
這是一篇國(guó)外的文章,介紹如何通過(guò) WebRTC、OpenCV 和 WebSocket 技術(shù)實(shí)現(xiàn)在 Web 瀏覽器上的人臉識(shí)別,架構(gòu)在 Jetty 之上。
實(shí)現(xiàn)的效果包括:
還能識(shí)別眼睛
人臉識(shí)別的核心代碼:
頁(yè)面:
XML/HTML
<div> <videoidvideoid="live"width="320"height="240" autoplay style="display: inline;"></video> <canvaswidthcanvaswidth="320"id="canvas"height="240"style="display: inline;"></canvas> </div> <scripttypescripttype="text/javascript"> var video = $("#live").get()[0]; var canvas = $("#canvas"); var ctx = canvas.get()[0].getContext('2d'); navigator.webkitGetUserMedia("video", function(stream) { video.src = webkitURL.createObjectURL(stream); }, function(err) { console.log("Unable to get video stream!") } ) timer = setInterval( function () { ctx.drawImage(video, 0, 0, 320, 240); }, 250); </script>
JavaScript
publicclass FaceDetection { privatestaticfinal String CASCADE_FILE ="resources/haarcascade_frontalface_alt.xml"; privateint minsize = 20; privateint group = 0; privatedouble scale = 1.1; /** * Based on FaceDetection example from JavaCV. */ publicbyte[] convert(byte[] imageData) throws IOException { // create image from supplied bytearray IplImage originalImage = cvDecodeImage(cvMat(1, imageData.length,CV_8UC1, newBytePointer(imageData))); // Convert to grayscale for recognition IplImage grayImage = IplImage.create(originalImage.width(), originalImage.height(), IPL_DEPTH_8U, 1); cvCvtColor(originalImage, grayImage, CV_BGR2GRAY); // storage is needed to store information during detection CvMemStorage storage = CvMemStorage.create(); // Configuration to use in analysis CvHaarClassifierCascade cascade = newCvHaarClassifierCascade(cvLoad(CASCADE_FILE)); // We detect the faces. CvSeq faces = cvHaarDetectObjects(grayImage, cascade, storage, scale, group, minsize); // We iterate over the discovered faces and draw yellow rectangles around them. for (int i = 0; i < faces.total(); i++) { CvRect r = new CvRect(cvGetSeqElem(faces, i)); cvRectangle(originalImage, cvPoint(r.x(), r.y()), cvPoint(r.x() + r.width(), r.y() + r.height()), CvScalar.YELLOW, 1, CV_AA, 0); } // convert the resulting image back to an array ByteArrayOutputStream bout = new ByteArrayOutputStream(); BufferedImage imgb = originalImage.getBufferedImage(); ImageIO.write(imgb, "png", bout); return bout.toByteArray(); } }
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。