Quellcode durchsuchen

新活检:暂停实时人脸

Michael Wang vor 5 Jahren
Ursprung
Commit
48f7b96e3e

+ 16 - 3
src/features/OnlineExam/Examing/FaceMotion/FaceMotion.vue

@@ -147,6 +147,8 @@ import * as faceapi from "face-api.js";
 import MD5 from "js-md5";
 // import introJs from "intro.js";
 import throttle from "lodash-es/throttle";
+import { createNamespacedHelpers } from "vuex";
+const { mapMutations } = createNamespacedHelpers("examingHomeModule");
 
 // models path
 const modelsPath = "/models/20190620/";
@@ -294,6 +296,7 @@ export default {
     },
   },
   async created() {
+    this.updateIsDoingFaceLiveness(true);
     // console.log(faceapi);
     // console.log(faceapi.nets.tinyFaceDetector);
     this.$Spin.show({});
@@ -313,6 +316,7 @@ export default {
     this.run();
   },
   methods: {
+    ...mapMutations(["updateIsDoingFaceLiveness"]),
     async fetchData() {
       const examRecordDataId = this.$route.params.examRecordDataId;
       // 失败了再取
@@ -340,6 +344,7 @@ export default {
       this.faceBiopsyInfo = faceBiopsyInfo;
     },
     async closeMe() {
+      this.updateIsDoingFaceLiveness(false);
       const faceLiveResultData = await this.$httpPostRetry(
         "/api/ecs_oe_student/faceBiopsy/saveFaceBiopsyResult",
         this.finalResult
@@ -364,6 +369,7 @@ export default {
       this.behavingStartDate = null;
       this.happyFailedTimes = 0;
       this.singleFaceFailedTimes = 0;
+      this.totalDetectTimes = 0;
       const steps = this.faceBiopsyInfo.verifySteps
         // .filter(s => ["HAPPY", "SERIOUS"].includes(s.action))
         .map(s => {
@@ -551,6 +557,7 @@ export default {
         // if (result.length === 0) {
         //   document.body.appendChild(canvas2);
         // }
+        this.totalDetectTimes++;
       } else {
         result = await faceapi
           // .detectSingleFace(videoEl, options)
@@ -570,7 +577,10 @@ export default {
           // 只有不是调整人脸距离的时候增加失败次数
           this.singleFaceFailedTimes++;
         }
-        if (this.singleFaceFailedTimes >= 5) {
+        if (
+          this.singleFaceFailedTimes >= 3 &&
+          this.singleFaceFailedTimes / this.totalDetectTimes >= 0.2
+        ) {
           this.corFinalResult.result = false;
           this.corFinalResult.errorMsg =
             "活检过程中没有检测到人脸!活体检测失败!";
@@ -738,7 +748,10 @@ export default {
           }
         }
         const detectEndTime = performance.now();
-        console.log("single detect time: ", detectEndTime - detectStartTime);
+        console.log(
+          "live single detect time: ",
+          detectEndTime - detectStartTime
+        );
         if (this.shouldDetectExpression && this.behavingStartDate) {
           // 到指定区块后才开始检测表情
           if (result.expressions.happy < 0.5 && this.currentStep.happy) {
@@ -774,7 +787,7 @@ export default {
               }
             }
           }
-          if (this.happyFailedTimes >= 6) {
+          if (this.happyFailedTimes / this.totalDetectTimes >= 0.4) {
             this.corFinalResult.result = false;
             this.corFinalResult.errorMsg = "指定表情失败!活体检测失败!";
             this.failedTest("指定表情失败!活体检测失败!");

+ 12 - 0
src/features/OnlineExam/Examing/FaceTracking.vue

@@ -6,6 +6,8 @@
 import * as faceapi from "face-api.js";
 import { FACE_API_MODEL_PATH } from "@/constants/constants";
 import { mapGetters as globalMapGetters } from "vuex";
+import { createNamespacedHelpers } from "vuex";
+const { mapState } = createNamespacedHelpers("examingHomeModule");
 import { isThisMachineOwnByStudent } from "@/utils/util";
 
 window.faceapi = faceapi;
@@ -79,6 +81,7 @@ export default {
   name: "FaceTracking",
   computed: {
     ...globalMapGetters(["isEpcc"]),
+    ...mapState(["isDoingFaceLiveness"]),
   },
   async created() {
     await faceapi.nets.tinyFaceDetector.load(FACE_API_MODEL_PATH);
@@ -128,6 +131,7 @@ export default {
         this.singleTimeUsage > 10 * 1000 ||
         this.multipleTimeUsage > 0.5 * 1000
       ) {
+        console.log("关闭实时人脸检测,因为耗时过长", this.multipleTimeUsage);
         window._hmt.push([
           "_trackEvent",
           "正在考试页面",
@@ -135,6 +139,14 @@ export default {
         ]);
         return;
       }
+      if (this.isDoingFaceLiveness) {
+        console.log("正在活检,暂停实时人脸");
+        this.detectFacesTimeout = setTimeout(
+          () => this.detectFaces(),
+          10 * 1000
+        );
+        return;
+      }
 
       const videoEl = document.getElementById("video");
       // var canvas = document.createElement("canvas");

+ 4 - 0
src/store.js

@@ -37,6 +37,7 @@ const examingHomeModule = {
     questionAnswerFileUrl: [],
     pictureAnswer: {},
     uploadModalVisible: false,
+    isDoingFaceLiveness: false,
   },
   mutations: {
     updateRemainTime(state, remainTime) {
@@ -184,6 +185,9 @@ const examingHomeModule = {
     updateUploadModalVisible(state, payload) {
       state.uploadModalVisible = payload;
     },
+    updateIsDoingFaceLiveness(state, payload) {
+      state.isDoingFaceLiveness = payload;
+    },
   },
   actions: {},
   getters: {