虹软SDK的简单使用

Java实现人脸识别,但是又不会自己实现算法,找SDK时发现了虹软。虹软SDK具有免费、识别率高等优点,然后到网上搜这个SDK的教程,没搜到,就自己探索,发现它自带的官方文档其实介绍的挺全面的,本文是由官方文档改编。

虹软SDK的激活

首先到官网注册账号,然后新建应用,然后获取到APP_ID和SDK_KEY

然后点击下载SDK,下好之后的项目结构:

|---doc
| |---ARCSOFT_ARC_FACE_JAVA_DEVELOPER'S_GUIDE.pdf 开发说明文档
|---lib
|---|---Win32/x64/linux64
| |---|---libarcsoft_face.dll 算法库
| |---|---libarcsoft_face_engine.dll 引擎库
| |---|---libarcsoft_face_engine_jni.dll 引擎库
| |---arcsoft-sdk-face-3.0.0.0.jar java依赖库
|---samplecode
| |---FaceEngineTest.java 示例代码
|---releasenotes.txt 说明文件

这里介绍的是windows版本,要将这三个.dll文件所在的文件夹添加到环境变量里面的Path里面去

再把下载的文件里面的jar包导入到项目里面去

然后就可以开始激活了

import com.arcsoft.face.FaceEngine;
import com.arcsoft.face.enums.ErrorInfo;/*** @author xuziao* @date 2021/8/21 12:44*/public class FaceTestMd {public void engineTest() {String appId = "你的APP_ID";String sdkKey = "你的SDK_KEY";//实例化一个面部引擎FaceEngine faceEngine = new FaceEngine();//这个SDK几乎每一个调用引擎的操作都会返回一个int类型的结果,称为错误码,每一种错误码对应一种程序执行的结果,如果错误对应着错误类型,可以去官网查这个码对应的错误int errorCode = faceEngine.activeOnline(appId, sdkKey);if (errorCode != ErrorInfo.MOK.getValue() &&errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {System.out.println("引擎激活失败:" + errorCode);} else {System.out.println("引擎激活成功");}}public static void main(String[] args) {new FaceTestMd().engineTest();}
}

对引擎进行引擎配置和功能配置

package top.gostack.demo1;import com.arcsoft.face.EngineConfiguration;
import com.arcsoft.face.FaceEngine;
import com.arcsoft.face.FunctionConfiguration;
import com.arcsoft.face.enums.DetectMode;
import com.arcsoft.face.enums.DetectOrient;
import com.arcsoft.face.enums.ErrorInfo;/*** @author xuziao* @date 2021/8/21 12:44*/public class FaceTestMd {public void engineTest() {String appId = "";String sdkKey = "";FaceEngine faceEngine = new FaceEngine();int errorCode = faceEngine.activeOnline(appId, sdkKey);if (errorCode != ErrorInfo.MOK.getValue() &&errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {System.out.println("引擎激活失败:" + errorCode);} else {System.out.println("引擎激活成功");}//以下为引擎配置EngineConfiguration engineConfiguration = new EngineConfiguration();//设置为单张高精度识别engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);//人脸不旋转,为零度engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_0_ONLY);//识别的最小人脸比例 = 图片长边 / 人脸框长边的比值engineConfiguration.setDetectFaceScaleVal(16);//设置最多能检测的人脸数量engineConfiguration.setDetectFaceMaxNum(10);//以下为功能设置final FunctionConfiguration functionConfiguration = new FunctionConfiguration();//年龄检测functionConfiguration.setSupportAge(true);//启用支持人脸检测functionConfiguration.setSupportFaceDetect(true);//启用人脸识别functionConfiguration.setSupportFaceRecognition(true);//启用性别识别functionConfiguration.setSupportGender(true);//启用3D检测functionConfiguration.setSupportFace3dAngle(true);//启用RGB活体检测functionConfiguration.setSupportLiveness(true);//不启用IR活体检测functionConfiguration.setSupportIRLiveness(false);//需要防止纸张、屏幕等攻击可以传入 supportLiveness 和 supportIRLiveness, RGB 和 IR 活体检测//将额外的设置注入到引擎中engineConfiguration.setFunctionConfiguration(functionConfiguration);int errorCode2 = faceEngine.init(engineConfiguration);if (errorCode2 != ErrorInfo.MOK.getValue()) {System.out.println("初始化引擎失败");} else {System.out.println("初始化引擎成功");}}public static void main(String[] args) {new FaceTestMd().engineTest();}
}

经过以上的操作引擎初始化算是成功了,然后下面可以进行功能测试

人脸相似度比对

package top.gostack.demo1;import com.arcsoft.face.*;
import com.arcsoft.face.enums.DetectMode;
import com.arcsoft.face.enums.DetectOrient;
import com.arcsoft.face.enums.ErrorInfo;
import com.arcsoft.face.toolkit.ImageInfo;import java.io.File;
import java.util.ArrayList;
import java.util.List;import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;/*** @author xuziao* @date 2021/8/21 12:44*/public class FaceTestMd {public void engineTest() {String appId = "";String sdkKey = "";FaceEngine faceEngine = new FaceEngine();int errorCode = faceEngine.activeOnline(appId, sdkKey);if (errorCode != ErrorInfo.MOK.getValue() &&errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {System.out.println("引擎激活失败:" + errorCode);} else {System.out.println("引擎激活成功");}//以下为引擎配置EngineConfiguration engineConfiguration = new EngineConfiguration();//设置为单张高精度识别engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);//人脸不旋转,为零度engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_0_ONLY);//识别的最小人脸比例 = 图片长边 / 人脸框长边的比值engineConfiguration.setDetectFaceScaleVal(16);//设置最多能检测的人脸数量engineConfiguration.setDetectFaceMaxNum(10);//以下为功能设置final FunctionConfiguration functionConfiguration = new FunctionConfiguration();//年龄检测functionConfiguration.setSupportAge(true);//启用支持人脸检测functionConfiguration.setSupportFaceDetect(true);//启用人脸识别functionConfiguration.setSupportFaceRecognition(true);//启用性别识别functionConfiguration.setSupportGender(true);//启用3D检测functionConfiguration.setSupportFace3dAngle(true);//启用RGB活体检测functionConfiguration.setSupportLiveness(true);//不启用IR活体检测functionConfiguration.setSupportIRLiveness(false);//需要防止纸张、屏幕等攻击可以传入 supportLiveness 和 supportIRLiveness, RGB 和 IR 活体检测//将额外的设置注入到引擎中engineConfiguration.setFunctionConfiguration(functionConfiguration);int errorCode2 = faceEngine.init(engineConfiguration);if (errorCode2 != ErrorInfo.MOK.getValue()) {System.out.println("初始化引擎失败");} else {System.out.println("初始化引擎成功");}String imgPath1 = "F:/Spring/SpringMVC/workplace/Ace_Face/resources/wyy1.jpg";String imgPath2 = "F:/Spring/SpringMVC/workplace/Ace_Face/resources/wyy4.jpg";FaceFeature faceFeature1 = getFaceFeature(imgPath1, faceEngine);FaceFeature faceFeature2 = getFaceFeature(imgPath2, faceEngine);//人脸相似度FaceSimilar faceSimilar = new FaceSimilar();int errorCode5 = faceEngine.compareFaceFeature(faceFeature1, faceFeature2, faceSimilar);if (errorCode5 != ErrorInfo.MOK.getValue()) {System.out.println("人脸对比操作失败!");} else {System.out.println("人脸对比成功!");System.out.println("人脸相似度:" + faceSimilar.getScore());}}/**** @param imgPath 传入图片的地址* @param faceEngine 传入引擎* @return faceFeature 输出的人脸特征信息*/public FaceFeature getFaceFeature(String imgPath, FaceEngine faceEngine) {//这个getRGBData方法内部调用了几个awt包里面的方法来处理图像数据,由此得到图像数据ImageInfo imageInfo = getRGBData(new File(imgPath));//新建一个人脸信息列表,获取到的人脸信息将储存在这个列表里面List<FaceInfo> faceInfoList = new ArrayList<>();//向引擎传入从图片分离的信息数据int errorCode3 = faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(),imageInfo.getImageFormat(), faceInfoList);if (errorCode3 != ErrorInfo.MOK.getValue()) {System.out.println("数据传入失败");} else {System.out.println("数据传入成功");System.out.println(faceInfoList);}//下面提取人脸特征FaceFeature faceFeature = new FaceFeature();int errorCode4 = faceEngine.extractFaceFeature(imageInfo.getImageData(),imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(),faceInfoList.get(0), faceFeature);if (errorCode4 != ErrorInfo.MOK.getValue()) {System.out.println("人脸特征提取失败!");} else {System.out.println("人脸特征提取成功!");System.out.println("特征值大小:" + faceFeature.getFeatureData().length);}return faceFeature;}public static void main(String[] args) {new FaceTestMd().engineTest();}
}

其余的还有年龄检测,活体检测,性别检测等等,其中在官方文档里面介绍的很清楚,我就不再一一赘述了,直接放上的测试代码和结果

我的测试代码

package top.gostack.demo1;import com.arcsoft.face.*;
import com.arcsoft.face.enums.DetectMode;
import com.arcsoft.face.enums.DetectOrient;
import com.arcsoft.face.enums.ErrorInfo;
import com.arcsoft.face.toolkit.ImageInfo;import java.io.File;
import java.util.ArrayList;
import java.util.List;import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;/*** @author xuziao* @date 2021/8/19 19:12*/public class FaceTest {public void engineTest() {String appId = "";String sdkKey = "";FaceEngine faceEngine = new FaceEngine();int errorCode = faceEngine.activeOnline(appId, sdkKey);if (errorCode != ErrorInfo.MOK.getValue() &&errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()){System.out.println("引擎激活失败:"+errorCode);} else {System.out.println("引擎激活成功");}//以下为引擎配置EngineConfiguration engineConfiguration = new EngineConfiguration();//设置为单张高精度识别engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);//人脸不旋转,为零度engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_0_ONLY);//识别的最小人脸比例 = 图片长边 / 人脸框长边的比值engineConfiguration.setDetectFaceScaleVal(16);//设置最多能检测的人脸数量engineConfiguration.setDetectFaceMaxNum(10);//以下为功能设置final FunctionConfiguration functionConfiguration = new FunctionConfiguration();//年龄检测functionConfiguration.setSupportAge(true);//启用支持人脸检测functionConfiguration.setSupportFaceDetect(true);//启用人脸识别functionConfiguration.setSupportFaceRecognition(true);//启用性别识别functionConfiguration.setSupportGender(true);//启用3D检测functionConfiguration.setSupportFace3dAngle(true);//启用RGB活体检测functionConfiguration.setSupportLiveness(true);//不启用IR活体检测functionConfiguration.setSupportIRLiveness(false);//需要防止纸张、屏幕等攻击可以传入 supportLiveness 和 supportIRLiveness, RGB 和 IR 活体检测//将额外的设置注入到引擎中engineConfiguration.setFunctionConfiguration(functionConfiguration);int errorCode2 = faceEngine.init(engineConfiguration);if (errorCode2 != ErrorInfo.MOK.getValue()) {System.out.println("初始化引擎失败");} else {System.out.println("初始化引擎成功");}String imgPath1 = "F:/Spring/SpringMVC/workplace/Ace_Face/resources/wyy1.jpg";String imgPath2 = "F:/Spring/SpringMVC/workplace/Ace_Face/resources/wyy4.jpg";FaceFeature faceFeature1 = getFaceFeature(imgPath1, faceEngine);FaceFeature faceFeature2 = getFaceFeature(imgPath2, faceEngine);//人脸相似度FaceSimilar faceSimilar = new FaceSimilar();int errorCode5 = faceEngine.compareFaceFeature(faceFeature1, faceFeature2, faceSimilar);if (errorCode5 != ErrorInfo.MOK.getValue()) {System.out.println("人脸对比操作失败!");} else {System.out.println("人脸对比成功!");System.out.println("人脸相似度:" + faceSimilar.getScore());}int errorCode11 = faceEngine.unInit();if (errorCode11 != ErrorInfo.MOK.getValue()) {System.out.println("引擎卸载失败,错误码:");System.out.println(errorCode);} else {System.out.println("引擎卸载成功!");}}/**** @param imgPath 传入图片的地址* @param faceEngine 传入引擎* @return faceFeature 输出的人脸特征信息*/public FaceFeature getFaceFeature(String imgPath, FaceEngine faceEngine) {//这个getRGBData方法内部调用了几个awt包里面的方法来处理图像数据,由此得到图像数据ImageInfo imageInfo = getRGBData(new File(imgPath));//新建一个人脸信息列表,获取到的人脸信息将储存在这个列表里面List<FaceInfo> faceInfoList = new ArrayList<>();//向引擎传入从图片分离的信息数据int errorCode3 = faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(),imageInfo.getImageFormat(), faceInfoList);if (errorCode3 != ErrorInfo.MOK.getValue()) {System.out.println("数据传入失败");} else {System.out.println("数据传入成功");System.out.println(faceInfoList);}//以下实现属性提取,提取某个属性要启用相关的功能FunctionConfiguration functionConfiguration = new FunctionConfiguration();functionConfiguration.setSupportAge(true);functionConfiguration.setSupportFace3dAngle(true);functionConfiguration.setSupportGender(true);functionConfiguration.setSupportLiveness(true);faceEngine.process(imageInfo.getImageData(), imageInfo.getWidth(),imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList, functionConfiguration);//下面提取属性,首先实现process接口int errorCode6 = faceEngine.process(imageInfo.getImageData(), imageInfo.getWidth(),imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList, functionConfiguration);if (errorCode6 != ErrorInfo.MOK.getValue()) {System.out.println("process接口调用失败,错误码:"+errorCode6);} else {System.out.println("process接口调用成功!");}//年龄检测//创建一个存储年龄的列表List<AgeInfo> ageInfoList = new ArrayList<>();int errorCode7 = faceEngine.getAge(ageInfoList);if (errorCode7 != ErrorInfo.MOK.getValue()) {System.out.print("获取年龄失败,错误码:");System.out.println(errorCode7);} else {System.out.println("年龄获取成功!");System.out.println("年龄:" + ageInfoList.get(0).getAge());}//以下为性别检测//性别检测List<GenderInfo> genderInfoList = new ArrayList<GenderInfo>();int errorCode8 = faceEngine.getGender(genderInfoList);if (errorCode8 != ErrorInfo.MOK.getValue()) {System.out.print("获取性别失败,错误码:");System.out.println(errorCode8);} else {System.out.println("性别获取成功!");System.out.println("性别:" + genderInfoList.get(0).getGender());}//3D信息检测List<Face3DAngle> face3DAngleList = new ArrayList<Face3DAngle>();int errorCode9 = faceEngine.getFace3DAngle(face3DAngleList);if (errorCode9 != ErrorInfo.MOK.getValue()) {System.out.println("3D信息检测失败,错误码:"+errorCode9);} else {System.out.println("3D信息获取成功!");System.out.println("3D角度:" + face3DAngleList.get(0).getPitch() + "," +face3DAngleList.get(0).getRoll() + "," + face3DAngleList.get(0).getYaw());}//活体检测List<LivenessInfo> livenessInfoList = new ArrayList<LivenessInfo>();int errorCode10 = faceEngine.getLiveness(livenessInfoList);if (errorCode10 != ErrorInfo.MOK.getValue()) {System.out.println("活体检测失败,错误码:"+errorCode10);} else {System.out.println("活体检测成功");System.out.println("活体:" + livenessInfoList.get(0).getLiveness());}//下面提取人脸特征FaceFeature faceFeature = new FaceFeature();int errorCode4 = faceEngine.extractFaceFeature(imageInfo.getImageData(),imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(),faceInfoList.get(0), faceFeature);if (errorCode4 != ErrorInfo.MOK.getValue()) {System.out.println("人脸特征提取失败!");} else {System.out.println("人脸特征提取成功!");System.out.println("特征值大小:" + faceFeature.getFeatureData().length);}return faceFeature;}public static void main(String[] args) {new FaceTest().engineTest();}
}

运行结果:

引擎激活成功
初始化引擎成功
数据传入成功
[com.arcsoft.face.Rect(332, 152 - 924, 744),1]
process接口调用成功!
年龄获取成功!
年龄:21
性别获取成功!
性别:1
3D信息获取成功!
3D角度:-15.243982,21.721786,16.343493
活体检测成功
活体:1
人脸特征提取成功!
特征值大小:1032
数据传入成功
[com.arcsoft.face.Rect(345, 163 - 942, 760),1]
process接口调用成功!
年龄获取成功!
年龄:20
性别获取成功!
性别:1
3D信息获取成功!
3D角度:-11.13369,0.69471675,17.24398
活体检测成功
活体:1
人脸特征提取成功!
特征值大小:1032
人脸对比成功!
人脸相似度:0.9812902
引擎卸载成功!

最后注意,要学习这个SDK一定去看官方文档,写的很详细!

虹软人脸识别SDK的简单使用相关推荐

  1. 虹软人脸识别SDK接入Milvus实现海量人脸快速检索

    虹软人脸识别SDK接入Milvus实现海量人脸快速检索 背景 虹软SDK及Milvus简介 开发环境 虹软人脸识别SDK使用简介 Milvus环境搭建 快速检索实现 人脸识别流程简介 快速检索 虹软S ...

  2. SpringBoot 基于向量搜索引擎及虹软人脸识别SDK的大规模人脸搜索

    SpringBoot 基于向量搜索引擎及虹软人脸识别SDK的大规模向量数据搜索 文章目录 SpringBoot 基于向量搜索引擎及虹软人脸识别SDK的大规模向量数据搜索 在线环境demo 在线环境说明 ...

  3. 初次使用虹软人脸识别SDK C++版本

    本文章是基于虹软人脸识别SDK3.0,VS2019 首先,下载虹软人脸识别SDK,按照此目录下的PDF文件完成工程配置. 配置完成后,需要在以下目录将从官网获取的APPID以及SDKKEY进行填写,然 ...

  4. java用虹软人脸识别SDK实现人脸识别,运行ArcSoft的Java版本Demo出错,未检出人脸

    java.lang.UnsatisfiedLinkError: Can't load library: d:\face_libs\libarcsoft_ java用虹软人脸识别SDK实现人脸识别 网上 ...

  5. java用虹软人脸识别SDK实现人脸识别,运行ArcSoft的Java版本Demo出错,未检出人脸(已解决)

    java用虹软人脸识别SDK实现人脸识别,运行ArcSoft的Java版本Demo出错,未检出人脸问题已解决!!! 原因: 虹软人脸识别SDK版本问题! 下载的java版本的demo的SDK是arcs ...

  6. 虹软java接摄像头_虹软人脸识别SDK在网络摄像头中的实际应用

    目前在人脸识别领域中,网络摄像头的使用很普遍,但接入网络摄像头和人脸识别SDK有一定门槛,在此篇中介绍过虹软人脸识别SDK的接入流程,本文着重介绍网络摄像头获取视频流并处理的流程(红色框内),以下内容 ...

  7. 虹软人脸识别SDK的使用

    虹软人脸识别SDK使用说明 使用虹软平台需要先注册开发者账号: https://ai.arcsoft.com.cn/ucenter/user/userlogin 注册完成后进行登录,然后进行创建应用: ...

  8. 虹软java接摄像头_虹软人脸识别SDK(java+linux/window) 初试

    虹软人脸识别全平台demo调用-快速上手之服务端Windows篇 demo名称:ArcFace 2.2 Windows(86) Demo [C++] 一 环境配置: 1) 安装VS2013环境安装包( ...

  9. 虹软人脸识别 SDK 使用 Unity Android C# Java多语言开发 2021-09-06

    Unity接入虹软人脸识别Android版SDK == 自改aar包开发Android应用 下方有下载链接所有 demo aar 包== 文章目录 Unity接入虹软人脸识别Android版SDK 简 ...

最新文章

  1. 老段mysql,老段视频汇总
  2. ARM嵌入式开发之JTAG与SWD接口
  3. java轻量级Http Server
  4. Python 37 进程池与线程池 、 协程
  5. linux查看删除init内容,linux常用命令
  6. Vue的watch和computed属性
  7. 高级点的php书,深入理解php:高级技巧、面向对象与核心技术(原书第3版) 中文pdf扫描版[76MB]...
  8. Try increasing heap size with java option '-Xmxlt;sizegt;’.
  9. 计算机科学与技术考研多少分算高分,清华计算机科学与技术系考研初复试高分经验分享...
  10. Spring项目跟Axis2结合
  11. ETCD数据库源码分析——etcdserver bootstrap初始化存储
  12. java 游戏打砖块_基于JAVA的打砖块游戏
  13. CentOS更改语言两种方式
  14. 项目质量管理工具--鱼骨图(石川图)
  15. 计算机领域nt=p,计算机考试范题-pwerpoint操作.doc
  16. excel 2种方法将长日期修改成短日期
  17. 项目经验之谈--驱动崩溃分析之栈回溯技术与反汇编
  18. fpga挂一片ddr2_FPGA上外挂DDR2DDR3MIG IP的使用记录
  19. 核心板在麻醉系统中的应用
  20. 如何成为一个程序员:短,全面,个人摘要

热门文章

  1. 我觉得做运营月薪8000比做程序员月薪10000+好多了
  2. 编译原理习题(含答案)——2程序设计语言及其文法——哈工大陈鄞配套版本
  3. nanovna使用说明_陌筱镜头附件其他 适用于NanoVNA 矢量网络分析仪 天线分析仪 短波 MF HF VHF UHF 天分【价格 图片 品牌 报价】-苏宁易购东运数码专营店...
  4. 解决STM32不能模拟仿真的问题
  5. css旋转无效果问题
  6. 马云清华演讲:没用过支付宝 不知道怎么用
  7. C语言中的string头文件解析
  8. MPI 归约操作简介
  9. 华为OD机试之英文输入法(Java源码)
  10. 公司注册需要什么资料?