【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 分钟前
HarmonyOS5云服务技术分享--账号登录文章整理
华为·华为云·harmonyos
Francek Chen10 分钟前
【华为鸿蒙电脑】首款鸿蒙电脑发布:MateBook Fold 非凡大师 & MateBook Pro,擎云星河计划启动
人工智能·华为·电脑·harmonyos·matebook
深光标准技术14 分钟前
OpenHarmony开源鸿蒙兼容性测试常见问题解答分享
华为·开源·harmonyos
龚礼鹏15 分钟前
OpenHarmony 5.0设置应用设置手势导航开关打开后重新关闭导航栏和设置界面重合
华为·harmonyos
lqj_本人1 小时前
UniApp 实现的文件预览与查看功能#三方框架 #Uniapp
uni-app·harmonyos
ChinaDragonDreamer5 小时前
HarmonyOS:使用PickerController将编辑后的图片替换原图
harmonyos·鸿蒙
bestadc6 小时前
鸿蒙 Location Kit(位置服务)
harmonyos
爱笑的眼睛116 小时前
HarmonyOS Navigation组件深度解析与应用实践
harmonyos·harmonyos next
鸿蒙布道师6 小时前
鸿蒙NEXT开发动画案例9
android·ios·华为·harmonyos·鸿蒙系统·arkui·huawei