1
1
<script setup>
2
- import * as faceapi from " face-api.js " ;
2
+ import * as faceapi from " @vladmandic/ face-api" ;
3
3
import { onMounted , reactive , watch } from " vue" ;
4
4
5
5
/** 属性状态 */
@@ -12,7 +12,6 @@ const state = reactive({
12
12
netsOptions: {
13
13
ssdMobilenetv1: undefined ,
14
14
tinyFaceDetector: undefined ,
15
- mtcnn: undefined ,
16
15
},
17
16
/** 目标图片数据匹配对象 */
18
17
faceMatcher: {},
@@ -25,49 +24,57 @@ const state = reactive({
25
24
{
26
25
name: " 张伟" ,
27
26
imgs: [
28
- " /images/zw/face/zw01.png" ,
29
- " /images/zw/face/zw02.png" ,
30
- " /images/zw/face/zw03.png" ,
31
- " /images/zw/face/zw04.png" ,
27
+ ` /images/zw/face/zw01.png` ,
28
+ ` /images/zw/face/zw02.png` ,
29
+ ` /images/zw/face/zw03.png` ,
30
+ ` /images/zw/face/zw04.png` ,
32
31
],
33
32
},
34
33
{
35
34
name: " 曾小贤" ,
36
35
imgs: [
37
- " /images/zxx/face/zxx01.png" ,
38
- " /images/zxx/face/zxx02.png" ,
39
- " /images/zxx/face/zxx03.png" ,
40
- " /images/zxx/face/zxx04.png" ,
36
+ ` /images/zxx/face/zxx01.png` ,
37
+ ` /images/zxx/face/zxx02.png` ,
38
+ ` /images/zxx/face/zxx03.png` ,
39
+ ` /images/zxx/face/zxx04.png` ,
41
40
],
42
41
},
43
42
],
44
43
});
45
44
46
45
/** 初始化模型加载 */
47
46
async function fnLoadModel () {
47
+ // 模型文件访问路径
48
+ const modelsPath = ` /models` ;
48
49
// 面部轮廓模型
49
- await faceapi .loadFaceLandmarkModel ( " /models " );
50
+ await faceapi .nets . faceLandmark68Net . load (modelsPath );
50
51
// 面部识别模型
51
- await faceapi .loadFaceRecognitionModel ( " /models " );
52
+ await faceapi .nets . faceRecognitionNet . load (modelsPath );
52
53
53
54
// 模型参数-ssdMobilenetv1
54
- await faceapi .nets .ssdMobilenetv1 .loadFromUri ( " /models " );
55
+ await faceapi .nets .ssdMobilenetv1 .load (modelsPath );
55
56
state .netsOptions .ssdMobilenetv1 = new faceapi.SsdMobilenetv1Options ({
56
- minConfidence: 0.6 , // 0.1 ~ 0.9
57
+ minConfidence: 0.5 , // 0 ~ 1
58
+ maxResults: 50 , // 0 ~ 100
57
59
});
58
60
// 模型参数-tinyFaceDetector
59
- await faceapi .nets .tinyFaceDetector .loadFromUri ( " /models " );
61
+ await faceapi .nets .tinyFaceDetector .load (modelsPath );
60
62
state .netsOptions .tinyFaceDetector = new faceapi.TinyFaceDetectorOptions ({
61
- inputSize: 512 , // 160 224 320 416 512 608
62
- scoreThreshold: 0.5 , // 0.1 ~ 0.9
63
- });
64
- // 模型参数-mtcnn 已弃用,将很快被删除
65
- await faceapi .nets .mtcnn .loadFromUri (" /models" );
66
- state .netsOptions .mtcnn = new faceapi.MtcnnOptions ({
67
- minFaceSize: 20 , // 1 ~ 50
68
- scaleFactor: 0.709 , // 0.1 ~ 0.9
63
+ inputSize: 416 , // 160 224 320 416 512 608
64
+ scoreThreshold: 0.5 , // 0 ~ 1
69
65
});
70
66
67
+ // 输出库版本
68
+ console .log (
69
+ ` FaceAPI Version: ${
70
+ faceapi? .version || " (not loaded)"
71
+ } \nTensorFlow/ JS Version: ${
72
+ faceapi .tf ? .version_core || " (not loaded)"
73
+ } \nBackend: ${
74
+ faceapi .tf ? .getBackend () || " (not loaded)"
75
+ } \nModels loaded: ${faceapi .tf .engine ().state .numTensors } tensors`
76
+ );
77
+
71
78
// 节点元素
72
79
state.targetImgEl = document.getElementById("page_draw-img-target");
73
80
state.targetCanvasEl = document.getElementById("page_draw-canvas-target");
@@ -190,7 +197,6 @@ onMounted(() => {
190
197
<select v-model="state.netsType">
191
198
<option value="ssdMobilenetv1">SSD Mobilenet V1</option>
192
199
<option value="tinyFaceDetector">Tiny Face Detector</option>
193
- <option value =" mtcnn" >MTCNN</option >
194
200
</select>
195
201
</div>
196
202
<div style="color: #f44336">
0 commit comments