ソースを参照

fix detectSingleFace

Michael Wang 5 年 前
コミット
e537d254a1
1 ファイル変更9 行追加2 行削除
  1. 9 2
      src/features/OnlineExam/Examing/FaceMotion/FaceMotion.vue

+ 9 - 2
src/features/OnlineExam/Examing/FaceMotion/FaceMotion.vue

@@ -875,15 +875,22 @@ export default {
       console.log(videoEl.readyState, faceapi.nets.tinyFaceDetector.params);
       console.log("increaseTestSpeed --- doing faceapi");
       const result = await Promise.race([
+        // 检测单人脸,如果没有人脸,返回undefined
         faceapi
           .detectSingleFace(videoEl, options)
           .withFaceLandmarks()
           .withFaceExpressions(),
-        new Promise(resolve => setTimeout(resolve, 20 * 1000)),
+        new Promise(resolve =>
+          setTimeout(resolve, 20 * 1000, "detectionTimeout")
+        ),
       ]);
+      // const result = await faceapi
+      //   .detectSingleFace(videoEl, options)
+      //   .withFaceLandmarks()
+      //   .withFaceExpressions();
       console.log("increaseTestSpeed --- result:", result);
       this.$Spin.hide();
-      if (typeof result === "undefined") {
+      if (result === "detectionTimeout") {
         this.$Message.error({
           content: "人脸检测功能不可用",
           duration: 15,