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