【FAQ】HarmonyOS SDK 闭源开放能力 —Vision Kit (3)

1.问题描述:

通过CardRecognition识别身份证拍照拿到的照片地址,使用该方法获取不到图片文件,请问如何解决?

解决方案:

//卡证识别实现页,文件名为CardDemoPage,需被引入至入口页

import { CallbackParam, CardRecognition, CardSide, CardType, ShootingMode } from '@kit.VisionKit';

import { hilog } from '@kit.PerformanceAnalysisKit';

import { fileIo as fs } from '@kit.CoreFileKit';

import { image } from '@kit.ImageKit';

const TAG: string = 'CardRecognitionPage'

@Entry

@Component

export struct CardDemoPage {

@State cardDataSource: Record<string, string>[] = []

@Consume('pathStack') pathStack: NavPathStack

@State cardImageUri: string = '';

build() {

NavDestination() {

Stack({ alignContent: Alignment.Top }) {

Stack() {

this.cardDataShowBuilder()

}

.width('80%')

.height('80%')

CardRecognition({

// 此处选择身份证类型作为示例

supportType: CardType.CARD_ID,

cardSide: CardSide.BACK,

cardRecognitionConfig: {

defaultShootingMode: ShootingMode.MANUAL,

isPhotoSelectionSupported: true,

cardContentConfig: { bankCard: { isBankNumberDialogShown: true } }

},

callback: ((params: CallbackParam) => {

hilog.info(0x0001, TAG, params code: ${params.code})

if (params.code === -1) {

this.pathStack.pop()

}

hilog.info(0x0001, TAG, params cardType: ${params.cardType})

if (params.cardInfo?.front !== undefined) {

this.cardDataSource.push(params.cardInfo?.front)

}

if (params.cardInfo?.back !== undefined) {

this.cardDataSource.push(params.cardInfo?.back)

}

if (params.cardInfo?.main !== undefined) {

this.cardDataSource.push(params.cardInfo?.main)

}

hilog.info(0x0001, TAG, params cardInfo front: ${JSON.stringify(params.cardInfo?.front)})

hilog.info(0x0001, TAG, params cardInfo back: ${JSON.stringify(params.cardInfo?.back)})

this.cardImageUri = params.cardInfo?.back?.cardImageUri as string

this.getPixelMap()

})

})

}

.width('100%')

.height('100%')

}

.width('100%')

.height('100%')

.hideTitleBar(true)

}

getPixelMap() {

try {

hilog.info(0x0001, TAG, getPixelMap cardImageUri: + this.cardImageUri)

let file = fs.openSync(this.cardImageUri, fs.OpenMode.READ_ONLY)

if (!file) {

hilog.info(0x0001, TAG, getPixelMap file: + file)

}

hilog.info(0x0001, TAG, "getPixelMap fd: " + file.fd)

const imageSource: image.ImageSource = image.createImageSource(file.fd);

let pixMap = imageSource.createPixelMapSync();

hilog.info(0x0001, TAG, "getPixelMap pixMap: " + pixMap)

} catch (error) {

hilog.error(0x0000, 'testTag', 'getPixelMap failed: %{public}s', JSON.stringify(error));

}

}

@Builder

cardDataShowBuilder() {

List() {

ForEach(this.cardDataSource, (cardData: Record<string, string>) => {

ListItem() {

Column() {

Image(cardData.cardImageUri)

.objectFit(ImageFit.Contain)

.width(100)

.height(100)

Text(JSON.stringify(cardData))

.width('100%')

.fontSize(12)

}

}

})

}

.listDirection(Axis.Vertical)

.alignListItem(ListItemAlign.Center)

.margin({

top: 50

})

.width('100%')

.height('100%')

}

}

2.问题描述:

基于门禁等需要人脸识别的场景,需要录入面部信息,鸿蒙如何实现面部识别功能?

解决方案:

人脸活体检测,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/vision-interactive-liveness-V5#section10727191484112,检测成功之后会返回最具有活体特征的图片,使用这张图片后面可以用人脸比对获取结果,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/core-vision-facecomparator-api-V5

3.问题描述:

升级到Beta5版本,身份证拍摄页面,调用卡证识别控件,身份证正面拍摄可以获取到照片,国徽面获取不到照片,Beta2版本正常,报13900002 No such file or directory 错误

解决方案:

在IDE右下角的Device File Browser进入手机目录结构,看一下图片是否存在。

或者在工程中用 fs.access 判断一下文件是否存在https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-file-fs-V5#fsaccess

CardSide说明:

FRONT 0 身份证人像面或其他卡证正面。

BACK 1 身份证国徽面或其他卡证反面。

DEFAULT 2 卡证默认面。如身份证为人像面和国徽面,护照为单面。

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/vision-card-recognition-V5#section1823389379

4.问题描述:

活体检测有没有安全性报告?用到交易开户场景是否涉及合规问题?

解决方案:

1-2周内会有CFCA认证报告,合规和安全问题需要伙伴结合自己的使用场景综合评估

</string,></string,>

相关推荐
安卓开发者12 分钟前
鸿蒙Next的AVSession Kit:重塑音视频播控的开发体验
华为·音视频·harmonyos
哦***712 分钟前
华为FreeBuds 7i空间音频不灵敏怎么办?
华为·音视频
鸿蒙小白龙1 小时前
鸿蒙openharmony操作系统LiteOS-A内核技术全解析:架构、性能与开发实践
华为·架构·harmonyos·鸿蒙·鸿蒙系统·open harmony
2503_928411564 小时前
10.23 @Observed深层监听
华为·harmonyos·鸿蒙
KongHen4 小时前
UTS编写字符串编解码/加密插件(安卓及鸿蒙端)
前端·harmonyos
做运维的阿瑞4 小时前
鸿蒙6.0技术解析:五大行业迎来的智能化革命
人工智能·harmonyos
鸿蒙Jy4 小时前
一篇文章带你理解什么是鸿蒙开发中V1&&V2装饰器
harmonyos
SunkingYang5 小时前
C++变量与函数命名规范技术指南 (基于华为编码规范与现代C++最佳实践)
c++·华为·编码规范·命名规则·命名规范·函数名字·成员变量
王嘉俊9255 小时前
HarmonyOS 项目入门:构建跨设备智能应用的强大框架
华为·harmonyos
Francek Chen5 小时前
【HarmonyOS 6 特别发布】鸿蒙 6 正式登场:功能升级,构建跨设备安全流畅新生态
人工智能·华为·harmonyos·harmonyos 6