提高人脸首次检测速度-api.js?
Improve speed of first detection in face-api.js?
在 face-api.js 中,检测照片的第一次调用大约需要 10 秒,然后所有后续检测都需要几毫秒。
有什么方法可以在开始检测之前调用一些函数来做准备,避免这种初始延迟吗?考虑到用户需要做一个动作(点击一个按钮)来启动人脸检测。
我已经在进行初始化引导加载。根据代码。
应用初始化()
const MODEL_URL = "/static/models";
faceapi.loadTinyFaceDetectorModel(MODEL_URL);
await faceapi.loadFaceLandmarkTinyModel(MODEL_URL);
await faceapi.loadFaceDetectionModel(MODEL_URL);
await faceapi.loadFaceRecognitionModel(MODEL_URL);
navigator.mediaDevices
.getUserMedia({ video: { frameRate: { ideal: 10, max: 15 } } })
.then(stream => {
this.cameraPreview.srcObject = stream;
this.cameraPreview.style.display = "block";
})
.catch(err => {
alert("error");
});
调用检测
start(){
configProcessFace();
detectFace();
}
configProcessFace() {
let inputSize = 128;
let scoreThreshold = 0.58;
this.faceOptions = new faceapi.TinyFaceDetectorOptions({
inputSize,
scoreThreshold
});
},
async detectFace() {
faceapi
.detectSingleFace(this.cameraPreview, this.faceOptions)
.run()
.then(res => {
if (res && res.box) {
...
}
window.setTimeout(() => {
this.detectFace();
}, 40);
})
.catch(err => {
console.log(err);
});
我推送一张有脸的图片,比例为 512x512,并在加载应用程序时进行了识别。当用户识别它时,需要 1 秒。
咨询:
prepareFaceDetector() {
let base_image = new Image();
base_image.src = "/static/img/startFaceDetect.jpg";
base_image.onload = function() {
const useTinyModel = true;
const fullFaceDescription = faceapi
.detectSingleFace(base_image, new faceapi.TinyFaceDetectorOptions())
.withFaceLandmarks(useTinyModel)
.withFaceDescriptor()
.run()
.then(res => {
console.log("--------> " + JSON.stringify(res));
});
};
}
在 face-api.js 中,检测照片的第一次调用大约需要 10 秒,然后所有后续检测都需要几毫秒。
有什么方法可以在开始检测之前调用一些函数来做准备,避免这种初始延迟吗?考虑到用户需要做一个动作(点击一个按钮)来启动人脸检测。
我已经在进行初始化引导加载。根据代码。
应用初始化()
const MODEL_URL = "/static/models";
faceapi.loadTinyFaceDetectorModel(MODEL_URL);
await faceapi.loadFaceLandmarkTinyModel(MODEL_URL);
await faceapi.loadFaceDetectionModel(MODEL_URL);
await faceapi.loadFaceRecognitionModel(MODEL_URL);
navigator.mediaDevices
.getUserMedia({ video: { frameRate: { ideal: 10, max: 15 } } })
.then(stream => {
this.cameraPreview.srcObject = stream;
this.cameraPreview.style.display = "block";
})
.catch(err => {
alert("error");
});
调用检测
start(){
configProcessFace();
detectFace();
}
configProcessFace() {
let inputSize = 128;
let scoreThreshold = 0.58;
this.faceOptions = new faceapi.TinyFaceDetectorOptions({
inputSize,
scoreThreshold
});
},
async detectFace() {
faceapi
.detectSingleFace(this.cameraPreview, this.faceOptions)
.run()
.then(res => {
if (res && res.box) {
...
}
window.setTimeout(() => {
this.detectFace();
}, 40);
})
.catch(err => {
console.log(err);
});
我推送一张有脸的图片,比例为 512x512,并在加载应用程序时进行了识别。当用户识别它时,需要 1 秒。
咨询:
prepareFaceDetector() {
let base_image = new Image();
base_image.src = "/static/img/startFaceDetect.jpg";
base_image.onload = function() {
const useTinyModel = true;
const fullFaceDescription = faceapi
.detectSingleFace(base_image, new faceapi.TinyFaceDetectorOptions())
.withFaceLandmarks(useTinyModel)
.withFaceDescriptor()
.run()
.then(res => {
console.log("--------> " + JSON.stringify(res));
});
};
}