接口调用流程

LFMultipleLivenessManager 调用流程

LFMultipleLivenessManager 是对LFMultipleLivenessController 调用流程进一步的封装,方便用户直接调用

1 初始化 LFMultipleLivenessManager 输入token

token

LFMultipleLivenessManager *manager = [[LFMultipleLivenessManager alloc] initLFLivenessWithToken:token];

2 配置 LFMultipleLivenessConfigItem 进行参数设置

LFMultipleLivenessConfigItem *configItem = [[LFMultipleLivenessConfigItem alloc] init];
configItem.openVoice = self.openVoice;
configItem.videoQuality = self.videoQuality;
[manager setLFLivenessConfig:configItem];

3 开始活体检测,设置present 活体检测视图控制器和代理

[manager startLFLivenessWithCurrentController:self multipleLivenessDelegate:self];

活体检测SDK的接口调用主要是LFLivefaceViewController。下面是详细介绍。

LFMultipleLivenessController 调用流程

LFMultipleLivenessController是对LFLivefaceViewController的一层封装,已经写好了一部分内部逻辑。如果没有内部定制化的要求,可以直接使用LFMultipleLivenessController。

1 遵守 LFLivenessDetectorDelegate 协议

@interface ViewController () <LFMultipleLivenessDelegate>

2 初始化参数设置

LFMultipleLivenessController * multipleLiveVC = [[LFMultipleLivenessController alloc] init];
multipleLiveVC.token = token;
[multipleLiveVC setJsonCommand:nil];

声音的开关,可以设置bOpenPromptSound来控制。

3 present 活体检测视图控制器

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:multipleLiveVC];
[navigationController setNavigationBarHidden:YES];
[self presentViewController:navigationController animated:YES completion:^{
        //如果需要自动开始,而不是按钮触发,调用下面这行代码
        //[multipleLiveVC restart];
}];

4 实现 LFMultipleLivenessDelegate 中的方法

//活体检测已经开始的回调.
- (void)LFMultiLivenessDidStart;
// 活体检测成功回调方法.
- (void)LFMultiLivenessDidSuccessfulGetData:(NSData *)encryTarData lfImages:(NSArray *)arrLFImage lfVideoData:(NSData *)lfVideoData;
// 活体检测失败回调方法.(可根据需要添加参数返回失败时的图片和视频)
- (void)LFMultiLivenessDidFailWithType:(LFMultipleLivenessError)iErrorType DetectionType:(LFDetectionType)iDetectionType DetectionIndex:(NSInteger)iIndex Data:(NSData *)encryTarData lfImages:(NSArray *)arrLFImage lfVideoData:(NSData *)lfVideoData;
// 取消活体检测指令回调方法.
- (void)LFMultiLivenessDidCancel;

LFLivefaceViewController调用流程

LFLivefaceViewController 是我们提供的活体检测SDK示例。可以根据界面提示,设置动作序列,以及是否打开提示音等操作。设置完成后,就可以开始进行检测。

下图为接口调用说明图。

流程介绍图

详细说明如下:

1 遵守 LFLivenessDetectorDelegate 协议

@interface ViewController () <LFLivenessDetectorDelegate>

2 获取资源路径

// 资源路径
NSString *strResourcesBundlePath = [[NSBundle mainBundle] pathForResource:@"lf_liveness_resource" ofType:@"bundle"];

3 初始化活体检测视图控制器

LFLivefaceViewController *livenessVC = [[LFLivefaceViewController alloc] initWithDuration:10.0f resourcesBundlePath:strResourcesBundlePath];

4 相关参数设置

你需要是否打开语音提示。SDK会根据您的设置,来进行活体检测。

// 设置代理及回调线程
[livenessVC setDelegate:self callBackQueue:dispatch_get_main_queue() detectionSequence:arrLivenessSequence];
// 设置默认语音提示状态,如不设置默认为开启
livenessVC.bVoicePrompt = YES;

6 校验Token 并present 活体检测视图控制器

detectVC.modalPresentationStyle = UIModalPresentationFullScreen;
[self.livefaceVC checkToken:self.token callback:^(NSString * _Nonnull token, NSDictionary * _Nonnull result) {
        NSNumber *checkResult = [result valueForKey:@"check_result"];
        if (checkResult.integerValue == 1) {
            [detectVC presentViewController:self animated:NO completion:^{
                [self restart];
            }];
        }
}];

5 实现 LFLivenessDetectorDelegate 中的方法

- (void)livenessDidStartDetectionWithDetectionType:(LivefaceDetectionType)iDetectionType
                                    detectionIndex:(int)iDetectionIndex;
{
    // 每个动作开始检测时会回调此方法
}

- (void)livenessTimeDidPast:(double)dPast durationPerModel:(double)dDurationPerModel
{
    // 检测开始后,当初始化检测器时如果Duration大于0则每帧都会回调此方法(示例程序中为10),dPast为当前动作已耗时,dDurationPerModel为每个动作设定的最大时间
}

// 活体检测成功的回调 , data为protobuf文件 , arrLFImage 为 LFImage 对象的数组, lfVideoData 为检测时的视频数据
- (void)livenessDidSuccessfulGetData:(NSData *)data
                            lfImages:(NSArray *)arrLFImage
                         lfVideoData:(NSData *)lfVideoData
{

// 活体检测失败的回调 , iErrorType为失败的错误类型 , iDetectionType为失败时检测类型 , iDetectionIndex为失败时检测类型所在检测序列中的位置(0为第一个)
- (void)livenessDidFailWithErrorType:(LivefaceErrorType)iErrorType
                       detectionType:(LivefaceDetectionType)iDetectionType
                      detectionIndex:(int)iDetectionIndex
                                data:(NSData *)data
                            lfImages:(NSArray *)arrLFImage
                         lfVideoData:(NSData *)lfVideoData
{
}

// 活体检测取消的回调 , iDetectionType为活体检测取消时的检测类型 , iDetectionIndex为取消时检测类型所在检测序列中的位置(0 为第一个)
- (void)livenessDidCancelWithDetectionType:(LivefaceDetectionType)iDetectionType detectionIndex:(int)iDetectionIndex
{
}

results matching ""

    No results matching ""