#星计划# OpenHarmony人脸识别实现 原创

中软小助手
发布于 2024-1-9 10:01
浏览
0收藏

作者:温德华

一、简介

人脸识别,是基于人的脸部特征信息进行身份识别的一种生物识别技术。用摄像机或摄像头采集含有人脸的图像或视频流,并自动在图像中检测和跟踪人脸,进而对检测到的人脸进行脸部识别的一系列相关技术,通常也叫做人像识别、面部识别。

二、案例中使用的接口

接口 描述
GetRecognizePoints 获取人脸矩形框
FaceSearchInit 人脸模型注册以及识别模块初始化
FaceSearchRegister 人脸搜索识别注册
FaceSearchGetRecognize 获取人脸搜索识别结果

三、人脸检测

1、在工程本地放入几张带人脸的图片,并利用GetRecognizePoints接口去检测图片中是否存在人脸


let path = getContext(this).bundleCodeDir + '/entry/resources/rawfile/'

let FdPath = path + "fd_2_00.dat";

let FlPath = path + "pd_2_00_pts81.dat";

            seetfaceApi.GetRecognizePoints(`${getContext(this).bundleCodeDir}/entry/resources/rawfile/${item.path}`, FdPath, FlPath)

.then(result => {

    console.log(`GetRecognizePoints success, result: ${JSON.stringify(result)}`)

    item.setCheckResult(result)

    this.refresh()

})

.catch(ex => {

    console.log(`GetRecognizePoints exception: ${JSON.stringify(ex)}`)

    item.setCheckResult(undefined)

    this.refresh()

})

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.

四、人脸识别

1、调用FaceSearchInit接口,主要包含模型的注册以及识别模块的初始化


let path = getContext(this).bundleCodeDir + '/entry/resources/rawfile/'

let FdPath = path + "fd_2_00.dat";

let PdPath = path + "pd_2_00_pts5.dat";

let FrPath = path + "fr_2_10.dat";



seetfaceApi.FaceSearchInit(FdPath, PdPath, FrPath)

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

2、调用FaceSearchRegister接口,获取图片并注册人脸模型


let register = seetfaceApi.FaceSearchRegister({

name: item.name,

image[`${getContext(this).bundleCodeDir}/entry/resources/rawfile/${item.image}`],

sum: 1

})

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

3、调用FaceSearchGetRecognize接口,获取人脸识别结果


seetfaceApi.FaceSearchGetRecognize(`${getContext(this).bundleCodeDir}/entry/resources/rawfile/${item.path}`)

.then(result => {

    console.log(`GetRecognizePoints success, result: ${JSON.stringify(result)}`)

    item.setCheckResult(result)

    this.refresh()

})

.catch(ex => {

    console.log(`GetRecognizePoints exception: ${JSON.stringify(ex)}`)

    item.setCheckResult(undefined)

    this.refresh()

})

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.

总结

通过这些接口,可以实现人脸识别以及检测的功能,希望能帮到大家

更多原创内容请关注:中软国际 HarmonyOS 技术团队

入门到精通、技巧到案例,系统化分享HarmonyOS开发技术,欢迎投稿和订阅,让我们一起携手前行共建鸿蒙生态。

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
收藏
回复
举报
1
1条回复
按时间正序
/
按时间倒序
老头看IT
老头看IT

大神,可以出个seetfaceApi引入和编译的教程吗

回复
2024-4-12 14:53:07


回复
    相关推荐
    这个用户很懒,还没有个人简介
    帖子
    视频
    声望
    粉丝
    社区精华内容