0 Star 50 Fork 24

TsMask / face-api-demo-vue

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

face-api-demo-vue

使用 Vue 框架搭建演示,H5WebNodeJS 实现人脸检测识别,基于 TensorFlowJS 实现的 face-api.js 人脸识别库。

识别模型文件放在 public/models 目录下,部署时请确保网络路径能访问到模型文件。

npm 主要安装识别库:

# 升级版作者库
npm i --save @vladmandic/face-api
# 原作者库
# npm i --save face-api.js

安装识别库库后在 node_modules/@vladmandic/face-api/model 可以拿到模型文件。

其他

console.log(faceapi.nets);
// const nets: {
//     ssdMobilenetv1: SsdMobilenetv1;
//     tinyFaceDetector: TinyFaceDetector;
//     tinyYolov2: TinyYolov2;
//     faceLandmark68Net: FaceLandmark68Net;
//     faceLandmark68TinyNet: FaceLandmark68TinyNet;
//     faceRecognitionNet: FaceRecognitionNet;
//     faceExpressionNet: FaceExpressionNet;
//     ageGenderNet: AgeGenderNet;
// }
//
// 放在public/models内
// 载入模型
// await faceapi.nets.ssdMobilenetv1.load("/models");
// 通过url地址
// await faceapi.nets.ssdMobilenetv1.loadFromUri("/models");
// 本地相对路径
// await faceapi.nets.ssdMobilenetv1.loadFromDisk("../../public/models");

侦测人脸

  • detectAllFaces :检测图像中的所有脸部
  • detectSingleFace :检测图像中具有最高置信度得分的脸部

默认情况下,detectAllFacesdetectSingleFace 使用 SSD Mobilenet V1 人脸检测器。

您可以通过传递相应的 options 对象来指定面部检测器:

const detections1 = await faceapi.detectAllFaces(输入, 使用的模型参数)
const detections2 = await faceapi.detectSingleFace(输入, 使用的模型参数)

输入 :使用 HTMLImageElement | HTMLVideoElement | HTMLCanvasElement 类型

使用的模型参数 :配置识别度和修改人脸框,请看 识别库说明 或者 查阅文档

识别库工具

// 请求json格式文件数据 Any
const json = await faceapi.fetchJson("http://www.example.com/file/example.json");
// 请求视频文件 HTMLImageElement
const imageEl = await faceapi.fetchImage("http://www.example.com/file/example.jpg");
// 请求视频文件 HTMLVideoElement
const videoEl = await faceapi.fetchVideo("http://www.example.com/file/example.mp4");

// 从Blob/File对象创建HTMLImageElement
const imageEl = await faceapi.bufferToImage(fileBlob);

// 从图像或视频元素创建画布元素
const canvasEl = faceapi.createCanvasFromMedia(HTMLImageElement | HTMLVideoElement)

当前项目说明

示例参考 face-api.js 作者提供示例源码 examples-browser

内含功能:

  1. 脸标志检测
  2. 人脸表情识别
  3. 年龄和性别识别
  4. 人脸提取
  5. 人脸识别
  6. 人脸识别多图处理
  7. BBT 人脸识别
  8. BBT 图片相似度
  9. BBT 图片相似度多查找
  10. Video 人脸跟踪
  11. Video 人脸识别
  12. WebRTC 人脸跟踪
  13. WebRTC 人脸识别
  14. WebRTC 媒体流基础

编译执行环境:

  • NodeJS:nodejs@18.16.0
  • Vite:vite@5.2.8
  • Vue:vue@3.4.21
  • VueRouter:vue-router@4.3.0
  • face-api:@vladmandic/face-api@1.7.13

项目结构

face-api-demo-vue
┌─public                  目录-静态资源
├─src
│ ├─assets                目录-编译资源
│ ├─components            目录-复用组件
│ ├─router                目录-页面路由配置
│ ├─utils                 目录-常用函数工具
│ ├─views                 目录-页面视图
│ ├─App.vue               文件-配置App全局
│ └─main.js               文件-Vue初始化
├─index.html              文件-页面容器
├─package-lock.json       文件-项目依赖版本锁
├─package.json            文件-项目信息
├─README.md               文件-项目说明
└─vite.config.js          文件-Vite配置

Project setup / 项目依赖安装初始化

npm install
# 使用阿里源可以加速下载依赖库
npm install --registry https://registry.npmmirror.com

Compiles and hot-reloads for development / 项目编译热更新用于开发调试

npm run dev

Compiles and minifies for production / 项目编译打包用于部署

npm run build

Customize configuration / 更多脚手架配置

See Configuration Reference.

MIT License Copyright (c) 2021 TsMask Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

【Vue】使用 Vue框架搭建演示,H5、Web、NodeJS 实现人脸检测识别,基于 TensorFlowJS 实现的 face-api.js 人脸识别库。 展开 收起
JavaScript 等 3 种语言
MIT
取消

发行版 (3)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/TsMask/face-api-demo-vue.git
git@gitee.com:TsMask/face-api-demo-vue.git
TsMask
face-api-demo-vue
face-api-demo-vue
master

搜索帮助