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

相关推荐
想你依然心痛2 小时前
HarmonyOS 6(API 23)实战:基于悬浮导航、沉浸光感与HMAF的“数智视界“——PC端AI智能体沉浸式数据可视化分析工作台
华为·ar·harmonyos·智能体
前端不太难9 小时前
从单页面到系统化:鸿蒙 App 演进路径
华为·状态模式·harmonyos
想你依然心痛11 小时前
HarmonyOS 6(API 23)实战:基于悬浮导航、沉浸光感与HMAF的“文思智脑“——PC端AI智能体沉浸式智能写作工作台
人工智能·ar·harmonyos·ai写作
小雨青年11 小时前
鸿蒙 HarmonyOS 6 | Pura X Max 鸿蒙原生适配 09:展开态列表增加字段但不变复杂
华为·harmonyos
richard_yuu11 小时前
鸿蒙治愈游戏模块实战|四大轻量解压游戏、ArkTS动画交互与低功耗落地
游戏·交互·harmonyos
阿钱真强道15 小时前
24 鸿蒙LiteOS GPIO中断实战:从原理到上升沿/下降沿详解
harmonyos·中断·rk·liteos·开源鸿蒙·瑞芯微·rk2206
小崽崽116 小时前
华为云云主机 + DeepSeek|快速实现华为云DeepSeek大模型搭建“腾讯云代码助手”客户端集成DeepSeek模型
华为·华为云·腾讯云
cd_9492172117 小时前
鸿蒙系统下抖音存储空间不足怎么办?缓存清理教程
缓存·华为·harmonyos
轻口味20 小时前
HarmonyOS 6.1 全栈实战录 - 14 渲染树透镜:FrameNode 渲染状态感知与高性能 UI 调优实战
ui·华为·harmonyos
HwJack2020 小时前
HarmonyOS NEXT 游戏APP开发中如何正确拦截退出手势
游戏·华为·harmonyos