Skip to content

Instantly share code, notes, and snippets.

View santosh-more's full-sized avatar

Santosh N. S. More santosh-more

View GitHub Profile
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 }
@santosh-more
santosh-more / script-with-models-loading.js
Created November 6, 2019 08:16
script to load the models
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: {} },
@santosh-more
santosh-more / script.js
Created November 4, 2019 17:26
Simple snippet to start webcam
const video = document.getElementById('video')
function startVideo() {
navigator.mediaDevices.getUserMedia(
{ video: {} },
stream => {
video.srcObject = stream
},
err => console.error(err)
)
body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
@santosh-more
santosh-more / index.html
Created November 4, 2019 14:22
html file to show the video
<!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>