face-api实现人脸识别。

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之上实现的用于浏览器中人脸检测和人脸识别的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();

    // 调整尺寸
    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

下载完成,可以在index.html页面直接live-server运行。

模型介绍
  1. ageGenderNet 识别性别和年龄
  2. faceExpressionNet 识别表情,开心,沮丧,普通
  3. faceLandmark68Net 识别脸部特征用于mobilenet算法
  4. faceLandmark68TinyNet 识别脸部特征用于tiny算法
  5. faceRecognitionNet 识别人脸
  6. ssdMobilenetv1 google开源AI算法除库包含分类和线性回归
  7. tinyFaceDetector 比Google的mobilenet更轻量级,速度更快一点
  8. mtcnn 多任务CNN算法,一开浏览器就卡死
  9. tinyYolov2 识别身体轮廓的算法。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值