Skip to content

Instantly share code, notes, and snippets.

@deanhume
Last active July 24, 2022 00:48
Show Gist options
  • Save deanhume/f93d23155fe6431fbb84354dbc7822bb to your computer and use it in GitHub Desktop.
Save deanhume/f93d23155fe6431fbb84354dbc7822bb to your computer and use it in GitHub Desktop.
Face Detection - Shape Detection API
var image = document.getElementById('image');
// Does the current browser support the API?
if (window.FaceDetector) {
var faceDetector = new FaceDetector();
faceDetector.detect(image)
.then(faces => {
console.log(‘Faces found:’, faces.length);
// Loop through the results
for(var i = 0; i < faces.length; i++) {
const face = faces[i].boundingBox;
console.log(‘face.width’, face.width);
console.log(‘face.height’, face.height);
}
}).catch((err) => {
console.error("Face detection failed " + err);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment