瀏覽代碼

人脸识别判断

Michael Wang 6 年之前
父節點
當前提交
3641bca233

+ 16 - 0
http-test/sys.http

@@ -0,0 +1,16 @@
+POST https://ecs-dev.qmth.com.cn:8878/api/ecs_core/auth/login
+Content-Type: application/json;charset=UTF-8
+
+{"domain":"ecs-dev.qmth.com.cn",
+"accountValue":"20180613",
+"password":"180613",
+"accountType":"STUDENT_CODE"}
+
+
+@token = d991f4022c0949abaa238cbe823ba024
+@key = U_S_109_53286
+
+###
+GET https://ecs-dev.qmth.com.cn:8878/api/sys_param?org_id=109
+token: {{token}}
+key: {{key}}

+ 16 - 3
src/components/FaceRecognition/FaceRecognition.vue

@@ -31,7 +31,7 @@ export default {
     this.openCamera();
   },
   watch: {
-    closeCamera: function(newValue, oldValue) {
+    closeCamera: function(newValue) {
       if (newValue) {
         console.log("关闭摄像头");
         this.$refs.video.srcObject.getTracks().forEach(function(track) {
@@ -106,7 +106,6 @@ export default {
         "/" +
         fileName;
       await this.faceCompare(captureFilePath);
-      this.$emit("on-recognize-result", "something wrong");
     },
     async faceCompare(captureFilePath) {
       const res = await this.$http.get(
@@ -136,7 +135,7 @@ export default {
           }
         );
         const verifyResult = await faceCompareRes.json();
-        console.log("人脸检测结果: " + verifyResult);
+        console.log("人脸检测结果: ", verifyResult);
 
         // 告知服务器人脸检测结果
         const params = new URLSearchParams();
@@ -145,6 +144,20 @@ export default {
         await this.$http.post("/api/face_capture", params);
 
         // TODO: 识别成功、失败的通知或跳转
+
+        let pass = false;
+        if (verifyResult.faces2.length > 0) {
+          var confidence = verifyResult.confidence;
+          var thresholds = verifyResult.thresholds;
+          if (confidence && thresholds && confidence > thresholds["1e-4"]) {
+            pass = true;
+          }
+        }
+        this.$emit("on-recognize-result", {
+          error: null,
+          pass,
+          faceCount: verifyResult.faces2.length
+        });
       } catch (e) {
         console.log(e);
         this.$Message.error(e.message);

+ 27 - 6
src/features/OnlineExam/OnlineExamFaceCheckModal.vue

@@ -40,7 +40,8 @@ export default {
     return { userPhoto: null, closeCamera: false };
   },
   props: {
-    open: Boolean
+    open: Boolean,
+    course: Object
   },
   async created() {
     const res = await this.$http.get(
@@ -59,6 +60,16 @@ export default {
         "https://ecs-test-static.qmth.com.cn/student_base_photo/" +
         this.userPhoto;
     }
+
+    const sysRes = await this.$http.get("/api/sys_param", {
+      params: {
+        orgId: this.$store.state.user.rootOrgId
+      }
+    });
+
+    // FIXME: 将faceEnable和faceCheck放到global的state中
+    this.faceEnable = sysRes.data.faceEnable; // 模拟练习?
+    this.faceCheck = sysRes.data.faceCheck; // 考试
   },
   computed: {
     ...mapState(["faceCheckModalOpen"])
@@ -70,14 +81,24 @@ export default {
       this.toggleFaceCheckModal(false);
     },
     updateCameraState(modalVisible) {
-      console.log(modalVisible);
       this.closeCamera = !modalVisible;
     },
-    getFaceRecognitionResult(err, result) {
-      console.log(err);
-      if (!err) {
-        const { faceCount, verifyResult, fileName } = result;
+    getFaceRecognitionResult({ error, faceCount, pass }) {
+      if (error) {
+        console.log(error, faceCount, pass);
+        this.$Message.error(error);
+        return;
+      }
+      if (!pass && this.course.faceCheck) {
+        this.$Modal.confirm({
+          title: "郑重承诺",
+          content:
+            "我承诺由本人参加考试,并且同意接受考试监控系统信息审核,一经发现作弊,立即取消本门课程考试成绩。",
+          onOk: () => this.$router.push("/online-practice")
+        });
+        return;
       }
+      this.$router.push("/online-practice");
     }
   },
   components: {

+ 3 - 2
src/features/OnlineExam/OnlineExamList.vue

@@ -31,7 +31,7 @@
       </tbody>
     </table>
 
-    <OnlineExamFaceCheckModal :open="faceCheckModalOpen"></OnlineExamFaceCheckModal>
+    <OnlineExamFaceCheckModal :open="faceCheckModalOpen" :course="selectedCourse"></OnlineExamFaceCheckModal>
   </div>
 </template>
 
@@ -46,7 +46,7 @@ const { mapState, mapMutations } = createNamespacedHelpers("examHomeModule");
 export default {
   name: "EcsOnlineList",
   data() {
-    return { now: new Date() };
+    return { now: new Date(), selectedCourse: null };
   },
   props: {
     courses: Array
@@ -76,6 +76,7 @@ export default {
         // if 人脸识别失败 && 考试开启强制人脸识别 return
         // if 人脸识别失败 && 考试未开启强制人脸识别
         //    让学生手动确认进入考试,若取消,则返回
+        this.selectedCourse = course;
         this.toggleFaceCheckModal(true);
       }