【发布时间】:2022-01-18 00:20:08
【问题描述】:
刚刚发现了很棒的face-api.js repo,我在使用面部表情 API 时玩得很开心。可能是因为我笑得太多了(为了测试)。
无论如何,在我的应用中,我想检查用户是否在微笑,但没有在屏幕上显示摄像头视频。
目前,我可以非常准确地检查用户是否在微笑,但视频必须在我的屏幕上。
如何从屏幕上删除视频?
这里是js代码:
<video id="video" width="500" height="500" autoplay muted ></video>
async startVideo() {
let stream = null;
try {
stream = await navigator.mediaDevices.getUserMedia({
audio: false,
video: { width: 1280, height: 720 },
});
this.video.srcObject = stream;
} catch (e) {
console.log(e);
}
},
this.video = document.getElementById('video');
Promise.all([
faceapi.nets.tinyFaceDetector.loadFromUri('/models'),
faceapi.nets.faceExpressionNet.loadFromUri('/models'),
]).then(this.startVideo);
this.video.addEventListener('play', () => {
console.log('video started');
setInterval(async () => {
const detections = await faceapi.detectAllFaces(
this.video,
new faceapi.TinyFaceDetectorOptions(),
).withFaceExpressions();
detections.forEach((detection) => {
if (detection.expressions.happy >= 0.7) {
this.isHappy = true;
} else {
this.isHappy = false;
}
});
}, 100);
});
应用在 vue.js 中,所以我只取了重要的部分。
非常感谢您的帮助。 干杯,
【问题讨论】:
标签: javascript canvas html5-video face-api