Kaynağa Gözat

优化inputSize选择

Michael Wang 5 yıl önce
ebeveyn
işleme
005648f595
1 değiştirilmiş dosya ile 20 ekleme ve 11 silme
  1. 20 11
      src/features/OnlineExam/Examing/FaceTracking.vue

+ 20 - 11
src/features/OnlineExam/Examing/FaceTracking.vue

@@ -69,19 +69,28 @@ async function detectTest() {
       await new Promise(resolve => setTimeout(resolve, 3 * 1000));
       const inputSize = inputSizeList[idx];
       const videoEl = document.getElementById("video");
-      const options = new faceapi.TinyFaceDetectorOptions({
-        inputSize: inputSize,
-        scoreThreshold: 0.5,
-      });
-      const result = await faceapi.detectAllFaces(videoEl, options);
-
-      if (result && result.length) {
-        console.log(`inputSize: ${inputSize} ${result.length}`);
-        succRate[idx]++;
-      } else {
-        console.log(`inputSize: ${inputSize} 检测失败`);
+      try {
+        const options = new faceapi.TinyFaceDetectorOptions({
+          inputSize: inputSize,
+          scoreThreshold: 0.5,
+        });
+        const result = await faceapi.detectAllFaces(videoEl, options);
+
+        if (result && result.length >= 1) {
+          console.log(`inputSize: ${inputSize} ${result.length}`);
+          succRate[idx]++;
+        } else {
+          console.log(`inputSize: ${inputSize} 检测失败`);
+        }
+      } catch (error) {
+        console.log(`inputSize: ${inputSize} 检测失败-异常`);
       }
     }
+
+    if (succRate[idx] === 10) {
+      console.log(`inputSize: ${inputSizeList[idx]} 提前选中`);
+      break;
+    }
   }
 
   console.log({ succRate });