Last active
March 9, 2019 04:16
-
-
Save supachaic/7f0ff690a22ea2af177c73daff2bc792 to your computer and use it in GitHub Desktop.
src/api/face.js
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
import * as faceapi from 'face-api.js'; | |
// Load models and weights | |
export async function loadModels() { | |
const MODEL_URL = process.env.PUBLIC_URL + '/models'; | |
await faceapi.loadTinyFaceDetectorModel(MODEL_URL); | |
await faceapi.loadFaceLandmarkTinyModel(MODEL_URL); | |
await faceapi.loadFaceRecognitionModel(MODEL_URL); | |
} | |
export async function getFullFaceDescription(blob, inputSize = 512) { | |
// tiny_face_detector options | |
let scoreThreshold = 0.5; | |
const OPTION = new faceapi.TinyFaceDetectorOptions({ | |
inputSize, | |
scoreThreshold | |
}); | |
const useTinyModel = true; | |
// fetch image to api | |
let img = await faceapi.fetchImage(blob); | |
// detect all faces and generate full description from image | |
// including landmark and descriptor of each face | |
let fullDesc = await faceapi | |
.detectAllFaces(img, OPTION) | |
.withFaceLandmarks(useTinyModel) | |
.withFaceDescriptors(); | |
return fullDesc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment