13-HarmonyOS5-VisionKit-InteractiveLiveness-Case

4 hours ago 2

Case Study of Interactive Liveness Detection in VisionKit on HarmonyOS 5.0 Abstract This article introduces how to use @kit.VisionKit to implement the interactive liveness detection function in HarmonyOS 5.0. By creating the VisionKitInteractiveLiveness component, users can request camera permissions and start liveness detection.

import { abilityAccessCtrl } from '@kit.AbilityKit'; import { interactiveLiveness } from '@kit.VisionKit'; import { promptAction, router } from '@kit.ArkUI';

@Entry @Component struct VisionKitInteractiveLiveness {

aboutToAppear(): void { this.requestPermissions() } hasPermissions: boolean = false async requestPermissions() { const atManager = abilityAccessCtrl.createAtManager(); const res = await atManager.requestPermissionsFromUser(getContext(), ['ohos.permission.CAMERA']) this.hasPermissions = res.authResults.every(grantStatus => grantStatus === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) } async start () { if (this.hasPermissions) { const routerOptions: interactiveLiveness.InteractiveLivenessConfig = { isSilentMode: 'INTERACTIVE_MODE' as interactiveLiveness.DetectionMode, routeMode: 'back' as interactiveLiveness.RouteRedirectionMode, actionsNum: 2, } await interactiveLiveness.startLivenessDetection(routerOptions) } } build() { Column() { Button('Start Detection') .onClick(() => { this.start() }) } .height('100%') .width('100%') } }
Read Entire Article