无法使用flutter_face_api扫描Live Face

问题描述 投票:0回答:1

我试图扫描用户面部以保存用户 LivenessResponse,但它在这里不起作用,函数被调用但它没有扫描面部。这是函数

Future<void> startLiveness() async {
    try {
      // Start the liveness detection
      LivenessResponse result = await faceSdk.startLiveness(
        config: LivenessConfig(
          skipStep: [LivenessSkipStep.ONBOARDING_STEP],
        ),
        notificationCompletion: (notification) {
          print(notification.status);
        },
      );
      print('result image $result');

      if (result.image != null) {
        setState(() {
          _livenessResponse = result; // Save the liveness response
          _status = "Liveness scan successful!";
        });
      } else {
        setState(() {
          _status = "Liveness scan failed: No image captured.";
        });
      }
    } catch (e) {
      setState(() {
        _status = "Liveness scan failed: ${e.toString()}";
      });
    }
  }

那么这里出了什么问题呢?因为没有捕捉到实时脸部,所以图像始终为空。

flutter face-recognition
1个回答
0
投票

试试这个代码。我在 notificationCompletion 回调中添加了增强的调试输出,以更好地了解活体扫描期间的人脸检测状态。

Future<void> startLiveness() async {
    try {
        // Start the liveness detection
        LivenessResponse result = await faceSdk.startLiveness(
            config: LivenessConfig(
                skipStep: [LivenessSkipStep.ONBOARDING_STEP],
            ),
            notificationCompletion: (notification) {
                print("Notification status: ${notification.status}");
                if (notification.status == "FACE_NOT_DETECTED") {
                    print("Face not detected, please adjust your position.");
                }
            },
        );
        print('Result: $result');

        if (result.image != null) {
            setState(() {
                _livenessResponse = result; // Save the liveness response
                _status = "Liveness scan successful!";
            });
        } else {
            setState(() {
                _status = "Liveness scan failed: No image captured.";
            });
        }
    } catch (e) {
        setState(() {
            _status = "Liveness scan failed: ${e.toString()}";
        });
        print("Error: $e");
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.