face-api的由來
訪問地址
JavaScript API for face detection and face recognition in the browser implemented on top of the tensorflow.js core API 官方說明
翻譯:在tensorflow.js核心API之上實現(xiàn)的用于瀏覽器中人臉檢測和人臉識別的JavaScript API
tensorflow.js 是什么
訪問tensorflow.js
部分代碼
const video = document.getElementById("video");
const startVideo = async () => {
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
video.srcObject = stream;
console.log(stream)
video.play();
};
Promise.all([
faceapi.nets.tinyFaceDetector.loadFromUri("./models"),
faceapi.nets.faceLandmark68Net.loadFromUri("./models"),
faceapi.nets.faceRecognitionNet.loadFromUri("./models"),
faceapi.nets.faceExpressionNet.loadFromUri("./models"),
]).then(startVideo());
video.addEventListener("play", () => {
// 制作定位 canvas
const canvas = document.createElement("canvas");
// canvas.style.position = "absolute";
document.body.append(canvas);
// 配置顯示尺寸
const displaySize = { width: video.width, height: video.height };
faceapi.matchDimensions(canvas, displaySize);
// 每 100ms 去繪制
setInterval(async () => {
// 識別位置, 臉部特征, 表情
const detections = await faceapi
.detectAllFaces(video, new faceapi.TinyFaceDetectorOptions())
.withFaceLandmarks()
.withFaceExpressions();
// 調(diào)整尺寸
const resizedDetections = faceapi.resizeResults(detections, displaySize);
canvas.getContext("2d")?.clearRect(0, 0, canvas.width, canvas.height); // 清空畫布
faceapi.draw.drawDetections(canvas, resizedDetections); // 位置
faceapi.draw.drawFaceLandmarks(canvas, resizedDetections); // 臉部特征
faceapi.draw.drawFaceExpressions(canvas, resizedDetections); // 表情
if (detections && detections.length > 0) {
}
}, 1000);
藍奏云:https://wwud.lanzouw.com/iLnE516oj2eh
百度云:https://pan.baidu.com/s/10CXGdfx1Q99TEefxSJUsBw?pwd=kutw
文章來源:http://www.zghlxwxcb.cn/news/detail-684213.html
下載完成,可以在index.html頁面直接live-server運行。文章來源地址http://www.zghlxwxcb.cn/news/detail-684213.html
模型介紹
- ageGenderNet 識別性別和年齡
- faceExpressionNet 識別表情,開心,沮喪,普通
- faceLandmark68Net 識別臉部特征用于mobilenet算法
- faceLandmark68TinyNet 識別臉部特征用于tiny算法
- faceRecognitionNet 識別人臉
- ssdMobilenetv1 google開源AI算法除庫包含分類和線性回歸
- tinyFaceDetector 比Google的mobilenet更輕量級,速度更快一點
- mtcnn 多任務CNN算法,一開瀏覽器就卡死
- tinyYolov2 識別身體輪廓的算法。
到了這里,關于face-api實現(xiàn)人臉識別。的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!