Browse Source

🎈 perf: 减少人脸识别时的出错次数

Pchen. 8 months ago
parent
commit
ca6f181924
1 changed files with 10 additions and 3 deletions
  1. 10 3
      src/pages/face/components/faceReco.vue

+ 10 - 3
src/pages/face/components/faceReco.vue

@@ -130,6 +130,7 @@ const state = reactive({
   recordingTimer: null,
   isRecording: false,
   lastBlob: null,
+  failCount: 0,
   uploading: false, // 上传状态
 })
 
@@ -275,9 +276,13 @@ async function fnRedrawDiscern() {
     .withFaceDescriptors()
 
   if (!detect || detect.length === 0) {
-    tagColor.value = 'blue'
-    tagInfo.value = '请将面部完全放置在取景框中央'
-    if (state.isRecording) stopRecording()
+    state.failCount++
+    if (state.failCount >= 3) {
+      tagColor.value = 'blue'
+      tagInfo.value = '请将面部完全放置在取景框中央'
+      if (state.isRecording) stopRecording()
+    }
+
     // 延迟下一次识别,避免直接递归造成栈/CPU 问题
     clearTimeout(state.timer)
     state.timer = setTimeout(() => fnRedrawDiscern(), 300)
@@ -297,12 +302,14 @@ async function fnRedrawDiscern() {
 
     if (best) {
       if (best._distance <= 0.6) {
+        state.failCount = 0
         tagColor.value = 'green'
         tagInfo.value = '录制中,请确保面部不要离开取景框'
         if (!state.isRecording) startRecording()
         // 找到一个合格的人脸就可以停止遍历
         break
       } else {
+        state.failCount = 3
         tagColor.value = 'red'
         tagInfo.value = `人脸匹配失败,请确保为 ${props?.userInfo?.name} 本人操作`
         if (state.isRecording) restartRecording()