目录
- 前言
- 卡证识别技术概述
- 关于卡证识别
- 使用场景
- 实现卡证识别步骤
结束语
前言
在众多应用场景中,比如金融、交通、身份验证等,卡证识别功能发挥着重要作用,尤其是在移动开发中越来越多的应用都涉及到卡证识别的功能。不用多讲,大家都清楚HarmonyOS提供了强大的机器学习能力,使得开发者能够轻松集成卡证识别功能到自己的应用中。那么本文就来详细介绍如何在HarmonyOS应用中实现卡证识别功能,包括技术选型、实现步骤和代码示例,方便大家学习使用。
卡证识别技术概述
先来了解一下卡证识别技术,卡证识别技术通常包括身份证、银行卡、驾驶证等证件的信息提取,这项技术涉及到图像处理、光学字符识别(OCR)等多个领域。在HarmonyOS中,可以通过集成华为机器学习服务(HMS Machine Learning Service)来实现卡证识别。
关于卡证识别
再来介绍在HarmonyOS中,卡证识别通常涉及的内容,具体如下步骤所示:
1.图像采集:获取卡证的图像。
2.图像预处理:对图像进行裁剪、旋转校正等操作。
3.特征提取:提取卡证上的关键信息。
4.信息识别:识别卡证上的文字信息。
5.结果处理:根据识别结果执行后续操作。使用场景
关于卡证识别的使用场景,鸿蒙开发中的卡证识别控件提供身份证(目前仅支持中国大陆二代身份证,且不包含民汉双文身份证)、行驶证、驾驶证、护照、银行卡等证件的结构化识别服务,满足卡证的自动分类功能,系统可自动判断所属卡证类型并返回结构化信息和卡证图片信息。
对于需要填充卡证信息的场景,如身份证、银行卡信息等,可使用卡证识别控件读取OCR(Optical Character Recognition)信息,将结果信息返回后进行填充。而且支持单独识别正面、反面,或同时进行双面识别。实现卡证识别步骤
在鸿蒙开发中实现卡证识别,大概从下面步骤操作。
步骤1:引入类文件
将卡证识别控件相关的类添加至工程中,具体如下所示:
//其中CardRecognitionConfig,CardContentConfig,BankCardConfig从5.0.0.36sdk开始支持
import { CardRecognition, CallbackParam, CardType, CardSide, CardRecognitionConfig, ShootingMode, CardContentConfig, BankCardConfig } from "@kit.VisionKit";
步骤2:配置页面布局
配置页面的布局,选择需要识别的卡证类型和需要识别的卡证页面,配置对应设置项,在回调中获取结果返回值。下面分别介绍身份证、银行卡、护照、驾驶证和行驶证的示例代码,具体操作如下所示:
// 身份证
import { hilog } from '@kit.PerformanceAnalysisKit';
const TAG = 'CardRecognition'
@Entry
@Component
struct Index {
build() {
Column() {
//身份证
CardRecognition({
supportType: CardType.CARD_ID,
// 身份证可双面识别
cardSide: CardSide.DEFAULT,
cardRecognitionConfig: {
defaultShootingMode: ShootingMode.MANUAL,
isPhotoSelectionSupported: true
},
callback: ((params: CallbackParam) => {
})
})
}
.height('100%')
.width('100%')
}
}
//银行卡
import { hilog } from '@kit.PerformanceAnalysisKit';
const TAG = 'CardRecognition'
@Entry
@Component
struct Index {
build() {
Column() {
// 银行卡
CardRecognition({
supportType: CardType.CARD_BANK,
// 银行卡为单面识别
cardSide: CardSide.FRONT,
cardRecognitionConfig: {
defaultShootingMode: ShootingMode.MANUAL,
isPhotoSelectionSupported: true,
cardContentConfig: { bankCard: { isBankNumberDialogShown: true} }
},
callback: ((params: CallbackParam) => {
})})
}
.height('100%')
.width('100%')
}
}
//护照
import { hilog } from '@kit.PerformanceAnalysisKit';
const TAG = 'CardRecognition'
@Entry
@Component
struct Index {
build() {
Column() {
// 护照
CardRecognition({
supportType: CardType.CARD_PASSPORT,
// 护照为单面识别
cardSide: CardSide.FRONT,
cardRecognitionConfig: {
defaultShootingMode: ShootingMode.MANUAL,
isPhotoSelectionSupported: true
},
callback: ((params: CallbackParam) => {
})})
}
.height('100%')
.width('100%')
}
}
//驾驶证
import { hilog } from '@kit.PerformanceAnalysisKit';
const TAG = 'CardRecognition'
@Entry
@Component
struct Index {
build() {
Column() {
// 驾驶证
CardRecognition({
supportType: CardType.CARD_DRIVER_LICENSE,
// 驾驶证可双面识别
cardSide: CardSide.DEFAULT,
cardRecognitionConfig: {
defaultShootingMode: ShootingMode.MANUAL,
isPhotoSelectionSupported: true
},
callback: ((params: CallbackParam) => {
})
})
}
.height('100%')
.width('100%')
}
}
//行驶证
import { hilog } from '@kit.PerformanceAnalysisKit';
const TAG = 'CardRecognition'
@Entry
@Component
struct Index {
build() {
Column() {
// 行驶证
CardRecognition({
supportType: CardType.CARD_VEHICLE_LICENSE,
// 行驶证可双面识别
cardSide: CardSide.DEFAULT,
cardRecognitionConfig: {
defaultShootingMode: ShootingMode.MANUAL,
isPhotoSelectionSupported: true
},
callback: ((params: CallbackParam) => {
})
})
}
.height('100%')
.width('100%')
}
}
最后分享一下关于银行卡识别示意图,具体如下图:
结束语
通过上面关于卡证识别的详细介绍,不难看出卡证识别是HarmonyOS开发中的一项强大功能,它为应用带来了更多的可能性和创新空间。尤其是通过本文的介绍,大家应该都了解了如何在HarmonyOS应用中实现卡证识别功能。随着技术的不断发展,卡证识别技术将在HarmonyOS生态中扮演越来越重要的角色,尤其是在现在越来越复杂的用户需求场景下,可以为用户带来更加丰富和便捷的体验。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。