您的位置:首页 > 文旅 > 旅游 > 鸿蒙AI功能开发【hiai引擎框架-人脸识别】 基础视觉服务-人脸检查

鸿蒙AI功能开发【hiai引擎框架-人脸识别】 基础视觉服务-人脸检查

2024/10/6 10:28:18 来源:https://blog.csdn.net/2301_76813281/article/details/140989986  浏览:    关键词:鸿蒙AI功能开发【hiai引擎框架-人脸识别】 基础视觉服务-人脸检查

介绍

本示例展示了使用hiai引擎框架提供的人脸识别能力。

本示例模拟了在应用里,选择一张图片,识别其多个人脸信息并展示出来。包括人脸框、五官点位、置信度、人脸朝向(欧拉角)

需要使用hiai引擎框架通用文字识别接口@hms.ai.face.faceDetector。

效果预览

1

使用说明:

  1. 在手机的主屏幕,点击”faceDetectorDemo“,启动应用。
  2. 点击“选择图片”按钮,默认自带一张图片,用户可以在图库中选择图片,或者通过相机拍照。
  3. 点击“开始识别”按钮,识别人脸信息,结果通过文本展示。

具体实现

本示例展示的控件在@@hms.ai.face.faceDetector.d.ets定义了文字识别API:

  • function detect(visionInfo: VisionInfo): Promise;

业务使用时,需要先进行import导入faceDetector 调用通用人脸识别接口,并传入想要识别的图片,接收处理返回的结果(文字信息)。参考:

import { faceDetector } from '@kit.CoreVisionKit';
import { image } from '@kit.ImageKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { picker, fileIo } from '@kit.CoreFileKit';@Entry
@Component
struct Index {private imageSource: image.ImageSource | undefined = undefined;@State chooseImage: PixelMap | undefined = undefined@State dataValues: string = ''build() {Column() {Image(this.chooseImage).objectFit(ImageFit.Fill).height('60%')Text(this.dataValues).copyOption(CopyOptions.LocalDevice).height('15%').margin(10).width('60%')Button('选择图片').type(ButtonType.Capsule).fontColor(Color.White).alignSelf(ItemAlign.Center).width('80%').margin(10).onClick(() => {// 拉起图库this.selectImage()})Button('开始识别').type(ButtonType.Capsule).fontColor(Color.White).alignSelf(ItemAlign.Center).width('80%').margin(10).onClick(async () => {if(!this.chooseImage) {hilog.error(0x0000, 'faceDetectorSample', `Failed to choose image. chooseImage: ${this.chooseImage}`);return;}// 调用人脸识别接口let visionInfo: faceDetector.VisionInfo = {pixelMap: this.chooseImage,};let data:faceDetector.Face[] = await faceDetector.detect(visionInfo);let faceString = data.toString();hilog.info(0x0000, 'faceDetectorSample', `Succeeded in face detect:${faceString}`);this.dataValues = faceString;})}.width('100%').height('100%').justifyContent(FlexAlign.Center)}private async selectImage() {let uri = await this.openPhoto()if (uri === undefined) {hilog.error(0x0000, 'faceDetectorSample', "Failed to defined uri.");}this.loadImage(uri)}private openPhoto(): Promise<string> {return new Promise<string>((resolve, reject) => {let photoPicker = new picker.PhotoViewPicker()photoPicker.select({MIMEType: picker.PhotoViewMIMETypes.IMAGE_TYPE, maxSelectNumber: 1}).then(res => {resolve(res.photoUris[0])}).catch((err: BusinessError) => {hilog.error(0x0000, 'faceDetectorSample', `Failed to get photo image uri. code:${err.code},message:${err.message}`);reject('')})})}private loadImage(name: string) {setTimeout(async () => {let fileSource = await fileIo.open(name, fileIo.OpenMode.READ_ONLY);this.imageSource = image.createImageSource(fileSource.fd);this.chooseImage = await this.imageSource.createPixelMap();}, 100)}
}

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

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

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

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

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

鸿蒙面经

在这里插入图片描述

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com