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

相关推荐
爱写Bug的浮游1 天前
初识仓颉:5 分钟看懂核心语法
harmonyos·编程语言
羽落•无痕(苏晗默)1 天前
华为数通IA——14、网络服务与应用:TCP/UDP 传输层协议与 FTP、Telnet、SSH 实践
网络·网络协议·tcp/ip·网络安全·华为·udp·信息与通信
程序猿追2 天前
鸿蒙 PC 的 Ionic 工单有两个错误,按下生成后光标该去哪儿
华为·harmonyos
KevinChaos2 天前
随手备忘录手记 04|HarmonyOS 7.0新特性实验:物品图鉴的加载逻辑
华为·harmonyos
Sirius_Ji2 天前
从硬解基座到字幕与滤镜链:ffmpeg-for-HarmonyOS v0.3.2
harmonyos
用户86194177207412 天前
uni-app 鸿蒙端提现点不动?我用 UTS 插件补上了微信"确认收款"
微信·harmonyos
码间留白2 天前
uni-app 鸿蒙端提现点不动?我用 UTS 插件补上了微信"确认收款"
uni-app·harmonyos·鸿蒙·uts插件·微信商家转账
GitCode官方3 天前
开源鸿蒙跨平台直播|AI 时代,用 cj-tauri 开发鸿蒙 PC 应用
人工智能·华为·harmonyos·atomgit
程序猿追3 天前
鸿蒙 PC 用 Tauri 做本地查找,怎样让慢请求给新请求让路
华为·状态模式·harmonyos
程序猿追3 天前
鸿蒙 PC 用 Ionic 做巡检目录,缩窄窗口后草稿还在吗
华为·harmonyos