This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
startVideo() | |
video.addEventListener('play', () => { | |
//create the canvas from video element as we have created above | |
const canvas = faceapi.createCanvasFromMedia(video); | |
//append canvas to body or the dom element where you want to append it | |
document.body.append(canvas) | |
// displaySize will help us to match the dimension with video screen and accordingly it will draw our detections | |
// on the streaming video screen | |
const displaySize = { width: video.width, height: video.height } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise.all([ | |
faceapi.nets.tinyFaceDetector.loadFromUri('/models'), | |
faceapi.nets.faceLandmark68Net.loadFromUri('/models'), | |
faceapi.nets.faceRecognitionNet.loadFromUri('/models'), | |
faceapi.nets.faceExpressionNet.loadFromUri('/models') | |
]).then(startVideo) | |
function startVideo() { | |
navigator.mediaDevices.getUserMedia( | |
{ video: {} }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const video = document.getElementById('video') | |
function startVideo() { | |
navigator.mediaDevices.getUserMedia( | |
{ video: {} }, | |
stream => { | |
video.srcObject = stream | |
}, | |
err => console.error(err) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 0; | |
padding: 0; | |
width: 100vw; | |
height: 100vh; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Face Recognition</title> | |
<link rel="stylesheet" href="style.css"> | |
<script defer src="face-api.min.js"></script> |