【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,>

相关推荐
梦想不只是梦与想1 天前
鸿蒙 应用市场更新功能:版本检测与更新提醒
harmonyos·鸿蒙·版本更新
xmdy58661 天前
Flutter+开源鸿蒙实战|智安盾电商溯源平台Day2 首页+核心入口UI开发(鸿蒙多端适配)
flutter·开源·harmonyos
nashane1 天前
HarmonyOS 6学习:HAR包与HSP包的选择与优化指南
学习·华为·harmonyos·harmonyos 5
全栈若城1 天前
自定义 TabBar 实战:浮动标签栏与舵式标签栏
harmonyos·harmonyos6·三方库开发
maaath1 天前
【maaath】Flutter for OpenHarmony 学习答题应用实战开发
学习·flutter·华为·harmonyos
李游Leo1 天前
别再拼 JSON 了:HarmonyOS UDMF 跨应用数据流转实践
harmonyos
maaath1 天前
【maaath】Flutter for OpenHarmony 实战:记账理财应用开发指南
flutter·华为·harmonyos
key_3_feng1 天前
鸿蒙6.0地图导航应用(可集成到其他APP)开发方案
华为·harmonyos
UnicornDev1 天前
【HarmonyOS 6】底部悬浮导航的沉浸光感适配(API23)
华为·harmonyos·arkts·鸿蒙·鸿蒙系统
轻口味1 天前
HarmonyOS 6 轻相机应用开发5:实时自动戴眼镜功能实现
数码相机·华为·harmonyos