当前位置: 首页 > news >正文

鸿蒙AI功能开发【人脸活体验证控件】 机器学习-场景化视觉服务

人脸活体验证控件

介绍

本示例展示了使用视觉类AI能力中的人脸活体验证能力。

本示例模拟了在应用里,跳转人脸活体验证控件,获取到验证结果并展示出来。

需要使用hiai引擎框架人脸活体验证接口@kit.VisionKit.d.ts。

效果预览

1

使用说明:

  1. 在手机的主屏幕,点击”faceDetectionDemo“,启动应用。
  2. 点击“开始检测”按钮,进入人脸检测验证控件。
  3. 验证结束后返回到主屏幕获取到验证结果并展示出来。

具体实现

本示例展示的控件在@kit.VisionKit.d.ts定义了活体检测API:

/*** Entry to the face liveness detection page.* The security camera needs to apply for network permissions.** @permission ohos.permission.CAMERA* @permission ohos.permission.INTERNET* @param { config } Liveness detection configuration item.* @returns { Promise<boolean> } Result of entering the liveness detection control.* @throws { BusinessError } 1008301002 Route switching failed.* @syscap SystemCapability.AI.Component.LivenessDetect* @atomicservice* @since 5.0.0(12)* */
function startLivenessDetection(config: InteractiveLivenessConfig): Promise<boolean>;/*** Obtains the face and liveness detection result.** @returns { Promise<InteractiveLivenessResult> } The results of the liveness test.* @throws { BusinessError } 1008302000 Detection algorithm initialization.* @throws { BusinessError } 1008302001 Detection timeout.* @throws { BusinessError } 1008302002 Action mutual exclusion error.* @throws { BusinessError } 1008302003 Continuity Check Failure.* @throws { BusinessError } 1008302004 The test is not complete.* @syscap SystemCapability.AI.Component.LivenessDetect* @atomicservice* @since 5.0.0(12)* */
function getInteractiveLivenessResult(): Promise<InteractiveLivenessResult>;

业务使用时,需要先进行import导入interactiveLiveness。 调用进入活体控件接口和验证结果接口,接收处理返回的结果。参考:

import { common, abilityAccessCtrl, Permissions } from '@kit.AbilityKit';
import { interactiveLiveness } from "@kit.VisionKit";
import { BusinessError } from '@kit.BasicServicesKit';@Entry
@Component
struct LivenessIndex {private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;private array: Array<Permissions> = ["ohos.permission.CAMERA"];@State actionsNum: number = 0;@State isSilentMode: string = 'INTERACTIVE_MODE';@State routeMode: string = 'replace';@State resultInfo: interactiveLiveness.InteractiveLivenessResult = {livenessType: 0};@State failResult: Record<string, number | string> = {'code': 1008302000,'message': ''};build() {Stack({alignContent: Alignment.Top}) {Column() {Row() {Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {Text('选择模式:').fontSize(18).width('25%')Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {Row() {Radio({ value: 'INTERACTIVE_MODE', group: 'isSilentMode' }).checked(true).height(24).width(24).onChange((isChecked: boolean) => {this.isSilentMode = 'INTERACTIVE_MODE'})Text('动作活体检测').fontSize(16)}.margin({ right: 15 })Row() {Radio({ value: 'SILENT_MODE', group: 'isSilentMode' }).checked(false).height(24).width(24).onChange((isChecked: boolean) => {this.isSilentMode = 'SILENT_MODE';})Text('静默活体检测').fontSize(16)}}.width('75%')}}.margin({ bottom: 30 })Row() {Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {Text('验证完的跳转模式:').fontSize(18).width('25%')Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {Row() {Radio({ value: 'replace', group: 'routeMode' }).checked(true).height(24).width(24).onChange((isChecked: boolean) => {this.routeMode = 'replace'})Text('replace').fontSize(16)}.margin({ right: 15 })Row() {Radio({ value: 'back', group: 'routeMode' }).checked(false).height(24).width(24).onChange((isChecked: boolean) => {this.routeMode = 'back';})Text('back').fontSize(16)}}.width('75%')}}.margin({ bottom: 30 })if (this.isSilentMode == 'INTERACTIVE_MODE') {Row() {Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {Text('动作数量:').fontSize(18).width('25%')TextInput({placeholder: this.actionsNum != 0 ? this.actionsNum.toString() : "动作数量最多4个"}).type(InputType.Number).placeholderFont({size: 18,weight: FontWeight.Normal,family: "HarmonyHeiTi",style: FontStyle.Normal}).fontSize(18).fontWeight(FontWeight.Bold).fontFamily("HarmonyHeiTi").fontStyle(FontStyle.Normal).width('65%').onChange((value: string) => {this.actionsNum = Number(value) as interactiveLiveness.ActionsNumber;})}}}}.margin({ left: 24, top: 80 }).zIndex(1)Stack({alignContent: Alignment.Bottom}) {if (this.resultInfo?.mPixelMap) {Image(this.resultInfo?.mPixelMap).width(260).height(260).align(Alignment.Center).rotate({ angle: 270 }).margin({ bottom: 260 })Circle().width(300).height(300).fillOpacity(0).strokeWidth(60).stroke(Color.White).margin({ bottom: 250, left: 0 })}Text(this.resultInfo.mPixelMap ?'检测成功' :this.failResult.code != 1008302000 ?'检测失败' :'').width('100%').height(26).fontSize(20).fontColor('#000000').fontFamily('HarmonyHeiTi').margin({ top: 50 }).textAlign(TextAlign.Center).fontWeight('Medium').margin({ bottom: 240 })if(this.failResult.code != 1008302000) {Text(this.failResult.message as string).width('100%').height(26).fontSize(16).fontColor(Color.Gray).textAlign(TextAlign.Center).fontFamily('HarmonyHeiTi').fontWeight('Medium').margin({ bottom: 200 })}Button("开始检测", { type: ButtonType.Normal, stateEffect: true }).width(192).height(40).fontSize(16).backgroundColor(0x317aff).borderRadius(20).margin({bottom: 56}).onClick(() => {this.privatestartDetection();})}.height('100%')}}onPageShow() {this.resultRelease();this.getDectionRsultInfo();}// 路由跳转到人脸活体验证控件private privaterouterLibrary() {let routerOptions: interactiveLiveness.InteractiveLivenessConfig = {'isSilentMode': this.isSilentMode as interactiveLiveness.DetectionMode,'routeMode': this.routeMode as interactiveLiveness.RouteRedirectionMode,'actionsNum': this.actionsNum}interactiveLiveness.startLivenessDetection(routerOptions).then((DetectState: boolean) => {console.info('LivenessCollectionIndex', `Succeeded in jumping.`);}).catch((err: BusinessError) => {console.error('LivenessCollectionIndex', `Failed to jump. Code:${err.code},message:${err.message}`);})}// 校验CAMERA权限private privatestartDetection() {let res = abilityAccessCtrl.createAtManager().verifyAccessTokenSync(100, "ohos.permission.CAMERA");if (res === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) {this.privaterouterLibrary();} else {abilityAccessCtrl.createAtManager().requestPermissionsFromUser(this.context, this.array, (err, res) => {for (let i = 0; i < res.permissions.length; i++) {if (res.permissions[i] === "ohos.permission.CAMERA" && res.authResults[i] === 0) {this.privaterouterLibrary();}}})}}// 获取验证结果private getDectionRsultInfo() {// getInteractiveLivenessResult接口调用完会释放资源let resultInfo = interactiveLiveness.getInteractiveLivenessResult();resultInfo.then(data => {this.resultInfo = data;}).catch((err: BusinessError) => {this.failResult = {'code': err.code,'message': err.message}})}// result releaseprivate resultRelease() {this.resultInfo = {livenessType: 0}this.failResult = {'code': 1008302000,'message': ''}}
}

以上就是本篇文章所带来的鸿蒙开发中一小部分技术讲解;想要学习完整的鸿蒙全栈技术。可以在结尾找我可全部拿到!
下面是鸿蒙的完整学习路线,展示如下:
1

除此之外,根据这个学习鸿蒙全栈学习路线,也附带一整套完整的学习【文档+视频】,内容包含如下

内容包含了:(ArkTS、ArkUI、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、鸿蒙南向开发、鸿蒙项目实战)等技术知识点。帮助大家在学习鸿蒙路上快速成长!

鸿蒙【北向应用开发+南向系统层开发】文档

鸿蒙【基础+实战项目】视频

鸿蒙面经

在这里插入图片描述

为了避免大家在学习过程中产生更多的时间成本,对比我把以上内容全部放在了↓↓↓想要的可以自拿喔!谢谢大家观看!

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 前端发版(发包)缓存,需要强制刷新问题处理
  • git版本控制的底层实现
  • Flink 实时数仓(四)【DWD 层搭建(二)流量域事实表】
  • enq: HW - contention事件来啦
  • fme从json中提取位置到kml中
  • react引入高德地图并初始化卫星地图
  • 【Go - 编译:浅尝辄止 】
  • 华为云全域Serverless技术创新:全球首创通用Serverless平台被ACM SIGCOMM录用
  • Android进阶之路 - 解决WebView加载H5时软键盘遮挡输入框问题
  • python的多线程
  • 自动化部署的艺术:Conda包依赖管理的终极指南
  • 从传统监控到智能化升级:EasyCVR视频汇聚平台的一站式解决方案
  • 春秋云境 | 文件上传 | CVE-2022-28525
  • linux文本处理命令:文本搜索工具grep详解
  • C++ | Leetcode C++题解之第322题零钱兑换
  • [js高手之路]搞清楚面向对象,必须要理解对象在创建过程中的内存表示
  • 【comparator, comparable】小总结
  • 【Linux系统编程】快速查找errno错误码信息
  • ➹使用webpack配置多页面应用(MPA)
  • docker容器内的网络抓包
  • HTML-表单
  • js如何打印object对象
  • MySQL用户中的%到底包不包括localhost?
  • Nginx 通过 Lua + Redis 实现动态封禁 IP
  • python学习笔记 - ThreadLocal
  • QQ浏览器x5内核的兼容性问题
  • rc-form之最单纯情况
  • 对JS继承的一点思考
  • 基于web的全景—— Pannellum小试
  • 前端每日实战 2018 年 7 月份项目汇总(共 29 个项目)
  • 实战|智能家居行业移动应用性能分析
  • 一个6年java程序员的工作感悟,写给还在迷茫的你
  • 一起参Ember.js讨论、问答社区。
  • 用jQuery怎么做到前后端分离
  • mysql 慢查询分析工具:pt-query-digest 在mac 上的安装使用 ...
  • ​iOS安全加固方法及实现
  • ‌内网穿透技术‌总结
  • ‌移动管家手机智能控制汽车系统
  • #[Composer学习笔记]Part1:安装composer并通过composer创建一个项目
  • #Linux(权限管理)
  • $.each()与$(selector).each()
  • (1)Android开发优化---------UI优化
  • (Java实习生)每日10道面试题打卡——JavaWeb篇
  • (二)【Jmeter】专栏实战项目靶场drupal部署
  • (附源码)springboot高校宿舍交电费系统 毕业设计031552
  • (附源码)springboot学生选课系统 毕业设计 612555
  • (没学懂,待填坑)【动态规划】数位动态规划
  • (十二)devops持续集成开发——jenkins的全局工具配置之sonar qube环境安装及配置
  • (推荐)叮当——中文语音对话机器人
  • (一)appium-desktop定位元素原理
  • (一)基于IDEA的JAVA基础1
  • (原創) 如何解决make kernel时『clock skew detected』的warning? (OS) (Linux)
  • (轉貼)《OOD启思录》:61条面向对象设计的经验原则 (OO)
  • .NET 2.0中新增的一些TryGet,TryParse等方法
  • .Net Redis的秒杀Dome和异步执行