Browse Source

Merge branch 'master' of http://git.ius.plus/Project-Vital/VitalApp

Melon 1 year ago
parent
commit
c793d90018
1 changed files with 3 additions and 194 deletions
  1. 3 194
      lib/pages/facial_recognition/controller.dart

+ 3 - 194
lib/pages/facial_recognition/controller.dart

@@ -12,7 +12,6 @@ import 'package:vitalapp/architecture/storage/storage.dart';
 import 'package:vitalapp/architecture/utils/prompt_box.dart';
 import 'package:vitalapp/managers/interfaces/cache.dart';
 import 'package:fis_common/logger/logger.dart';
-import 'package:vitalapp/pages/patient/list/controller.dart';
 import 'package:vitalapp/rpc.dart';
 import 'package:vitalapp/store/store.dart';
 import 'dart:ui' as ui;
@@ -350,9 +349,6 @@ class FacialRecognitionController extends GetxController
 
   /// 发生开始人脸识别事件
   void onCaptureFaceButtonPressed() {
-    // runDetectionTimer();
-    /// 接口测试
-    ///
     if (mode == FacialRecognitionMode.faceRecognition) {
       doFacialRecognitionTimes = 0;
       state.isRunningFaceRecognition = true;
@@ -364,6 +360,8 @@ class FacialRecognitionController extends GetxController
 
   /// 人脸识别执行次数
   int doFacialRecognitionTimes = 0;
+
+  /// 人脸识别逻辑
   void doFacialRecognition() async {
     doFacialRecognitionTimes++;
     if (doFacialRecognitionTimes == 10) {
@@ -434,7 +432,7 @@ class FacialRecognitionController extends GetxController
     doFacialRecognition();
   }
 
-  /// 人脸录入测试
+  /// 人脸录入逻辑
   void doFaceInput() async {
     if (kCameraController == null) {
       return;
@@ -488,112 +486,6 @@ class FacialRecognitionController extends GetxController
     }
   }
 
-  /// 发生结束录制视频事件
-  void onStopButtonPressed() {
-    stopVideoRecording().then((XFile? file) {
-      if (file != null) {
-        PromptBox.toast('Video recorded to ${file.path}');
-        // videoFile = file;
-        // _startVideoPlayer();
-      }
-      update();
-    });
-  }
-
-  /// 发生开始录制视频事件
-  void onVideoRecordButtonPressed() {
-    startVideoRecording().then((_) {
-      update();
-    });
-  }
-
-  /// 暂停录制视频
-  void onPauseButtonPressed() {
-    pauseVideoRecording().then((_) {
-      update();
-    });
-  }
-
-  /// 恢复视频录制
-  void onResumeButtonPressed() {
-    resumeVideoRecording().then((_) {
-      update();
-    });
-  }
-
-  /// 开始录制视频
-  Future<void> startVideoRecording() async {
-    final CameraController? cameraController = kCameraController;
-
-    if (cameraController == null || !cameraController.value.isInitialized) {
-      PromptBox.toast('Error: select a camera first.');
-      return;
-    }
-
-    if (cameraController.value.isRecordingVideo) {
-      // A recording is already started, do nothing.
-      return;
-    }
-
-    try {
-      await cameraController.startVideoRecording();
-    } on CameraException catch (e) {
-      PromptBox.toast('Error: ${e.code}\n${e.description}');
-      return;
-    }
-  }
-
-  /// 停止录制视频
-  Future<XFile?> stopVideoRecording() async {
-    final CameraController? cameraController = kCameraController;
-
-    if (cameraController == null || !cameraController.value.isRecordingVideo) {
-      return null;
-    }
-
-    try {
-      return cameraController.stopVideoRecording();
-    } on CameraException catch (e) {
-      PromptBox.toast('Error: ${e.code}\n${e.description}');
-
-      return null;
-    }
-  }
-
-  /// 暂停录制视频
-  Future<void> pauseVideoRecording() async {
-    final CameraController? cameraController = kCameraController;
-
-    if (cameraController == null || !cameraController.value.isRecordingVideo) {
-      return;
-    }
-
-    try {
-      await cameraController.pauseVideoRecording();
-    } on CameraException catch (e) {
-      PromptBox.toast('Error: ${e.code}\n${e.description}');
-
-      rethrow;
-    }
-  }
-
-  /// 恢复视频录制
-  Future<void> resumeVideoRecording() async {
-    final CameraController? cameraController = kCameraController;
-
-    if (cameraController == null || !cameraController.value.isRecordingVideo) {
-      return;
-    }
-
-    try {
-      await cameraController.resumeVideoRecording();
-    } on CameraException catch (e) {
-      PromptBox.toast('Error: ${e.code}\n${e.description}');
-
-      rethrow;
-    }
-  }
-
   /// 在 widget 内存中分配后立即调用。
   @override
   void onInit() async {
@@ -660,10 +552,7 @@ class FacialRecognitionController extends GetxController
     );
   }
 
-  /// WIP
   /// 面部识别 基于 Google's ML Kit
-  ///
-
   InputImage inputImage = InputImage.fromFilePath('');
   FaceDetector faceDetector = FaceDetector(options: FaceDetectorOptions());
 
@@ -677,84 +566,9 @@ class FacialRecognitionController extends GetxController
     final List<Face> faces = await faceDetector.processImage(inputImage);
     kFrameFacesResult = [];
     kFrameFacesResult.addAll(faces);
-
-    // for (Face face in faces) {
-    //   final Rect boundingBox = face.boundingBox;
-
-    //   final double? rotX =
-    //       face.headEulerAngleX; // Head is tilted up and down rotX degrees
-    //   final double? rotY =
-    //       face.headEulerAngleY; // Head is rotated to the right rotY degrees
-    //   final double? rotZ =
-    //       face.headEulerAngleZ; // Head is tilted sideways rotZ degrees
-
-    //   // If landmark detection was enabled with FaceDetectorOptions (mouth, ears,
-    //   // eyes, cheeks, and nose available):
-    //   final FaceLandmark? leftEar = face.landmarks[FaceLandmarkType.leftEar];
-    //   if (leftEar != null) {
-    //     final Point<int> leftEarPos = leftEar.position;
-    //   }
-
-    //   // If classification was enabled with FaceDetectorOptions:
-    //   if (face.smilingProbability != null) {
-    //     final double? smileProb = face.smilingProbability;
-    //   }
-
-    //   // If face tracking was enabled with FaceDetectorOptions:
-    //   if (face.trackingId != null) {
-    //     final int? id = face.trackingId;
-    //   }
-    // }
     return kFrameFacesResult.length;
   }
 
-  // bool isDetectionRunning = false;
-  Timer? _detectionTimer;
-
-  /// 开始持续检测人脸
-  // void runDetectionTimer() {
-  //   if (_detectionTimer != null) {
-  //     _detectionTimer!.cancel();
-  //     _detectionTimer = null;
-  //     faceDetector.close();
-  //     state.isShowFaceRecognitionResult = false;
-  //     return;
-  //   }
-  //   faceDetector =
-  //       FaceDetector(options: FaceDetectorOptions(enableContours: true));
-  //   state.isShowFaceRecognitionResult = true;
-
-  //   /// 记录最后一次拍摄的时间
-  //   int lastCaptureTime = DateTime.now().millisecondsSinceEpoch;
-  //   _detectionTimer = Timer.periodic(
-  //     const Duration(milliseconds: 300), // max 分辨率下拍摄用时大约 500ms-800ms
-  //     (timer) async {
-  //       if (kCameraController == null) {
-  //         return;
-  //       }
-  //       final XFile? file = await takePicture();
-  //       if (file != null) {
-  //         if (timer.tick == 1 || kFrameImageSize == Size.zero) {
-  //           Size imageSize = await getImageSize(file);
-  //           kFrameImageSize = imageSize;
-  //         }
-  //         int kTime = DateTime.now().millisecondsSinceEpoch;
-  //         print('⭐⭐⭐⭐⭐⭐⭐⭐ capture time: ${kTime - lastCaptureTime} ms');
-  //         lastCaptureTime = kTime;
-
-  //         /// 记录用时 ms
-  //         await doDetection(faceDetector, file.path); // max 分辨率下检测用时大约 100ms
-  //         int endTime = DateTime.now().millisecondsSinceEpoch;
-  //         print('⭐⭐⭐⭐⭐⭐⭐⭐ detection time: ${endTime - lastCaptureTime} ms');
-  //         update(['face_bounding_box']);
-  //         if (timer.tick >= 10) {
-  //           // finishFaceDetection(); // TODO 接入真实的判断条件
-  //         }
-  //       }
-  //     },
-  //   );
-  // }
-
   /// 用于将读取的视频流传给 Google ML
   InputImage cameraImageToInputImage(CameraImage cameraImage) {
     return InputImage.fromBytes(
@@ -790,11 +604,6 @@ class FacialRecognitionController extends GetxController
 
   /// 销毁检测器
   void closeDetector() {
-    if (_detectionTimer != null) {
-      state.isShowFaceRecognitionResult = false;
-      _detectionTimer!.cancel();
-      _detectionTimer = null;
-    }
     faceDetector.close();
   }
 }