慧定损

1. 慧定损 SDK 说明文档

1.1 简介

慧定损AR版通过AI引导用户在无需定损员干涉下自助拍摄定损视频和图片,进而基于拍摄的视频和图片完成自动定损。

1.2 当前版本

最新版本是 v1.0.0,2020年9月22日更新。
支持armv7、arm64的两种CPU架构。
此版安装包增量为6.9M(两个架构)。
支持 iOS9.0 以上系统。

2. 慧定损 SDK 集成说明

2.1 注意事项

license文件(DFLicense)用以控制程序的包名和有效时间(时间范围可以直接查看文件内容获取),请用户一定要确认程序的包名是否与 license 绑定的包名一致,请确保程序运行设备的系统时间在 license 的有效时间内。

2.2 SDK目录结构

目录

2.3 将SDK集成到开发环境

使用SDK前,首先需要将其集成到您的开发环境中。

配置开发环境

1. 导入SDK包

将libDFAIAssessor文件夹(包含 libDFAIAssessor.a、df_ai_assessor.bundle、.h、.m等) copy 一份到项目工程目录下,拖拽到 xcode 打开的工程中,勾选 copy,点击 Finish 按钮。

注:本 SDK 不支持 CocoaPods 的方式导入。

示例介绍图

2. 编译选项设置
2.1 需要手动关闭Bitcode。

步骤:

TARGETS -> BuildSettings -> Enable Bitcode 设置为 NO。

示例介绍图

3. 添加相关引用库。
  • 步骤: TARGETS ->Build Phases中添加相关引用库 示例介绍图

4. 调试iOS9以上系统时,调用相机功能时,在info.plist文件下添加隐私权限。
 <key>NSCameraUsageDescription</key>
 <string>cameraDesciption</string>
 <key> NSPhotoLibraryUsageDescription </key>
 <string>cameraDesciption</string>

2.4 开始检测

2.4.1集成检测界面

参考DFCaptureController.m调用

2.4.1.1初始化DFAIAssessorView。

参数DFAIAssessorConfigItem的介绍

 - (DFAIAssessorView *)setupAIAssessorViewWithFrame:(CGRect)frame
{
    DFAIAssessorConfigItem *configItem = [[DFAIAssessorConfigItem alloc] init];
    configItem.totalDetectCount = 5;
    configItem.classifySuccessCount = 3;
    configItem.minDetectTime = 4;
    configItem.intervalDetectCount = 5;
    configItem.differImageThreshold = 3 * 1000;
    configItem.intervalDamageCount = 5;
    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"df_ai_assessor" ofType:@"bundle"];
    NSString *licensePath = [NSString stringWithFormat:@"%@/DFLicense", bundlePath];
    DFAIAssessorView *view = [[DFAIAssessorView alloc] initWithFrame:frame configItem:configItem resourceBundlePath:bundlePath licensePath:licensePath delegate:self];
    [view enableVideoRecord:YES];
    return view;
}
2.4.1.2添加到父视图上。
    self.assessorView = [self setupAIAssessorViewWithFrame:bounds];
    [self.preview addSubview:self.assessorView];
2.4.1.3遵守协议DFAIAssessorViewDelegate
@interface DFCaptureController () <AVCaptureVideoDataOutputSampleBufferDelegate, DFAIAssessorViewDelegate>
2.4.1.4实现协议方法

初始化返回的错误码说明


#pragma mark - DFAIAssessorViewDelegate

- (void)initCompletedWithErrorCode:(DFAIAssessorViewError)errorCode
{
    // 初始化结束回调
    if (errorCode != DFAIAssessorViewErrorOK) {
        // 初始化失败
    } else {
        // 初始化成功
    }
}

- (void)detectCMSampleBufferResult:(NSArray<DFAIAssessorFrameItem *> *)frameResults
{
    // 返回抽帧信息
    for (DFAIAssessorFrameItem *item in frameResults) {
         // 保存图片到相册 test
        [self saveImage:item.image];
    }
}

- (void)detectFinishedVideoData:(NSData *)videoData encryptResut:(NSData *)encryptResut
{
    // 检测流程结束
    [self stopScanning];
    UIViewController *presentingViewController = self.presentingViewController;
    __weak typeof(self) weakSelf = self;
    [[[DFAlertView alloc] initWithMessages:@"是否继续拍摄其他损伤?" confirmTitle:@"完成" cancleTitle:@"继续" confirmBlock:^{
        [weakSelf dismissViewControllerAnimated:YES completion:^{
            [DFResultController presentResultControllerWithVideoData:videoData controller:presentingViewController];
        }];
    } cancelBlock:^{
        [weakSelf.assessorView restart];
        [weakSelf startScanning];
    }] show];
}

- (void)restartCallback
{
    // 重启检测
}

2.4.2传入检测数据

- (void)detectWithCMSampleBuffer:(CMSampleBufferRef)sampleBuffer;
  • 在相机回调中调用检测方法
 #pragma mark - AVCaptureVideoDataOutputSampleBufferDelegate

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
    UIDeviceOrientation toInterfaceOrientation = [UIDevice currentDevice].orientation;
    switch (toInterfaceOrientation) {
        case UIDeviceOrientationPortrait:
            [connection setVideoOrientation:AVCaptureVideoOrientationPortrait];
            break;
        case UIDeviceOrientationLandscapeLeft:
            [connection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
            break;
        case UIDeviceOrientationLandscapeRight:
            [connection setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft];
            break;
        default:
            [connection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
            break;
    }
    [self.assessorView detectWithCMSampleBuffer:sampleBuffer];
}

2.4.3继续检测

  • 当检测一次损伤结束之后,如果想继续检测其他损伤,请调用此方法
- (void)restart;
- (void)detectFinishedVideoData:(NSData *)videoData encryptResut:(NSData *)encryptResut
{
    // 检测流程结束
    [self stopScanning];
    UIViewController *presentingViewController = self.presentingViewController;
    __weak typeof(self) weakSelf = self;
    [[[DFAlertView alloc] initWithMessages:@"是否继续拍摄其他损伤?" confirmTitle:@"完成" cancleTitle:@"继续" confirmBlock:^{
        [weakSelf dismissViewControllerAnimated:YES completion:^{
            [DFResultController presentResultControllerWithVideoData:videoData controller:presentingViewController];
        }];
    } cancelBlock:^{
        [weakSelf.assessorView restart];
        [weakSelf startScanning];
    }] show];
}

results matching ""

    No results matching ""