人脸识别(Java实现的)
虹软人脸识别:
虹软人脸识别的地址:虹软视觉开放平台—以免费人脸识别技术为核心的人脸识别算法开放平台
依赖包:
依赖包是从虹软开发平台下载的

在项目中引入这个依赖包

pom.xml
<!-- 人脸识别 --><dependency><groupId>com.arcsoft.face</groupId><artifactId>arcsoft-sdk-face</artifactId><version>2.2.0.1</version><scope>system</scope><systemPath>${project.basedir}/lib/arcsoft-sdk-face-3.0.0.0.jar</systemPath></dependency>
打包:
<configuration><includeSystemScope>true</includeSystemScope>
</configuration>
如图:

需要的参数:
#虹软人脸识别参数
arcsoft.appid=JC1YjvrZrVXtJTTw9d68Jpzi95FY5kNAM5r98wft11111
arcsoft.sdkKey=EAFuucMzSpKymeCYqYwg4UC3QBbbMeMnw7NZBNRt1111
#驱动
arcsoft.libPath=D:\\Java\\faceDrive
驱动是需要引入代码中的

代码:
package com.example.tanhuanapp.server.impl;import com.arcsoft.face.EngineConfiguration;
import com.arcsoft.face.FaceEngine;
import com.arcsoft.face.FaceInfo;
import com.arcsoft.face.FunctionConfiguration;
import com.arcsoft.face.enums.DetectMode;
import com.arcsoft.face.enums.DetectOrient;
import com.arcsoft.face.enums.ErrorInfo;
import com.arcsoft.face.enums.ImageFormat;
import com.arcsoft.face.toolkit.ImageFactory;
import com.arcsoft.face.toolkit.ImageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.io.File;
import java.util.ArrayList;
import java.util.List;/*** @author IT空门_门主* @date 2024/1/11*/
@Slf4j
@Service
public class FaceEngineServiceImpl {@Value("${arcsoft.appid}")private String appid;@Value("${arcsoft.sdkKey}")private String sdkKey;@Value("${arcsoft.libPath}")private String libPath;private FaceEngine faceEngine;/*** 初始化引擎*/@PostConstructpublic void init() {// 激活并且初始化引擎FaceEngine faceEngine = new FaceEngine(libPath);int activeCode = faceEngine.activeOnline(appid, sdkKey);if (activeCode != ErrorInfo.MOK.getValue() && activeCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {log.error("引擎激活失败");throw new RuntimeException("引擎激活失败");}//引擎配置EngineConfiguration engineConfiguration = new EngineConfiguration();//IMAGE检测模式,用于处理单张的图像数据engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);//人脸检测角度,逆时针0度engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_0_ONLY);//功能配置FunctionConfiguration functionConfiguration = new FunctionConfiguration();functionConfiguration.setSupportAge(true);functionConfiguration.setSupportFace3dAngle(true);functionConfiguration.setSupportFaceDetect(true);functionConfiguration.setSupportFaceRecognition(true);functionConfiguration.setSupportGender(true);functionConfiguration.setSupportLiveness(true);functionConfiguration.setSupportIRLiveness(true);engineConfiguration.setFunctionConfiguration(functionConfiguration);//初始化引擎int initCode = faceEngine.init(engineConfiguration);if (initCode != ErrorInfo.MOK.getValue()) {log.error("初始化引擎出错!");throw new RuntimeException("初始化引擎出错!");}this.faceEngine = faceEngine;}/*** 检测图片是否为人像** @param imageInfo 图像对象* @return true:人像,false:非人像*/public boolean checkIsPortrait(ImageInfo imageInfo) {// 定义人脸列表List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList);log.info("检测到人脸数量:{}",faceInfoList.size());log.info("检测:{}",faceInfoList);return !faceInfoList.isEmpty();}/***上传图片接口(byte[])* @param imageData* @return*/public boolean checkIsPortrait(byte[] imageData) {return this.checkIsPortrait(ImageFactory.getRGBData(imageData));}/*** 上传图片接口(file)* @param file* @return*/public boolean checkIsPortrait(File file) {return this.checkIsPortrait(ImageFactory.getRGBData(file));}
}
测试:
package com.example.tanhuanapp;import com.arcsoft.face.*;
import com.arcsoft.face.enums.DetectMode;
import com.arcsoft.face.enums.DetectModel;
import com.arcsoft.face.enums.DetectOrient;
import com.arcsoft.face.enums.ErrorInfo;
import com.arcsoft.face.toolkit.ImageInfo;
import com.arcsoft.face.toolkit.ImageInfoEx;
import com.example.tanhuanapp.server.impl.FaceEngineServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import static com.arcsoft.face.toolkit.ImageFactory.getGrayData;
import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;/*** @author IT空门_门主* @date 2024/1/11*/
@Slf4j
@SpringBootTest
public class FaceRecognition {@Autowiredprivate FaceEngineServiceImpl faceEngineService;/*** 测试人脸识别*/@Testpublic void testCheckIsPortrait(){File file = new File("C:\\Users\\DELL\\Desktop\\aa\\1.jpg");boolean checkIsPortrait = this.faceEngineService.checkIsPortrait(file);System.out.println(checkIsPortrait); // true|false}@Testvoid contextLoads() {//从官网获取String appId = "JC1YjvrZrVXtJTTw9d68Jpzi95FY5kNAM5r98wftenQU";String sdkKey = "EAFuucMzSpKymeCYqYwg4UC3QBbbMeMnw7NZBNRtcGco";FaceEngine faceEngine = new FaceEngine("D:\\Java\\faceDrive");log.info("faceEngine:{}",faceEngine);//激活引擎int errorCode = faceEngine.activeOnline(appId, sdkKey);if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {System.out.println("引擎激活失败");}ActiveFileInfo activeFileInfo=new ActiveFileInfo();errorCode = faceEngine.getActiveFileInfo(activeFileInfo);if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {System.out.println("获取激活文件信息失败");}//引擎配置EngineConfiguration engineConfiguration = new EngineConfiguration();engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_ALL_OUT);engineConfiguration.setDetectFaceMaxNum(10);engineConfiguration.setDetectFaceScaleVal(16);//功能配置FunctionConfiguration functionConfiguration = new FunctionConfiguration();functionConfiguration.setSupportAge(true);functionConfiguration.setSupportFace3dAngle(true);functionConfiguration.setSupportFaceDetect(true);functionConfiguration.setSupportFaceRecognition(true);functionConfiguration.setSupportGender(true);functionConfiguration.setSupportLiveness(true);functionConfiguration.setSupportIRLiveness(true);engineConfiguration.setFunctionConfiguration(functionConfiguration);//初始化引擎errorCode = faceEngine.init(engineConfiguration);if (errorCode != ErrorInfo.MOK.getValue()) {System.out.println("初始化引擎失败");}//人脸检测ImageInfo imageInfo = getRGBData(new File("C:\\Users\\DELL\\Desktop\\aa\\21.jpg"));List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();errorCode = faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);System.out.println(faceInfoList);log.info("人脸检测接口返回值为{}", faceInfoList);//特征提取FaceFeature faceFeature = new FaceFeature();errorCode = faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList.get(0), faceFeature);System.out.println("特征值大小:" + faceFeature.getFeatureData().length);//人脸检测2ImageInfo imageInfo2 = getRGBData(new File("C:\\Users\\DELL\\Desktop\\aa\\21.jpg"));List<FaceInfo> faceInfoList2 = new ArrayList<FaceInfo>();errorCode = faceEngine.detectFaces(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(),imageInfo2.getImageFormat(), faceInfoList2);System.out.println(faceInfoList2);//特征提取2FaceFeature faceFeature2 = new FaceFeature();errorCode = faceEngine.extractFaceFeature(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(), imageInfo2.getImageFormat(), faceInfoList2.get(0), faceFeature2);System.out.println("特征值大小:" + faceFeature2.getFeatureData().length);//特征比对FaceFeature targetFaceFeature = new FaceFeature();targetFaceFeature.setFeatureData(faceFeature.getFeatureData());FaceFeature sourceFaceFeature = new FaceFeature();sourceFaceFeature.setFeatureData(faceFeature2.getFeatureData());FaceSimilar faceSimilar = new FaceSimilar();errorCode = faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);System.out.println("相似度:" + faceSimilar.getScore());//设置活体测试errorCode = faceEngine.setLivenessParam(0.5f, 0.7f);//人脸属性检测FunctionConfiguration configuration = new FunctionConfiguration();configuration.setSupportAge(true);configuration.setSupportFace3dAngle(true);configuration.setSupportGender(true);configuration.setSupportLiveness(true);errorCode = faceEngine.process(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList, configuration);//性别检测List<GenderInfo> genderInfoList = new ArrayList<GenderInfo>();errorCode = faceEngine.getGender(genderInfoList);System.out.println("性别:" + genderInfoList.get(0).getGender());//年龄检测List<AgeInfo> ageInfoList = new ArrayList<AgeInfo>();errorCode = faceEngine.getAge(ageInfoList);System.out.println("年龄:" + ageInfoList.get(0).getAge());//3D信息检测List<Face3DAngle> face3DAngleList = new ArrayList<Face3DAngle>();errorCode = faceEngine.getFace3DAngle(face3DAngleList);System.out.println("3D角度:" + face3DAngleList.get(0).getPitch() + "," + face3DAngleList.get(0).getRoll() + "," + face3DAngleList.get(0).getYaw());//活体检测List<LivenessInfo> livenessInfoList = new ArrayList<LivenessInfo>();errorCode = faceEngine.getLiveness(livenessInfoList);System.out.println("活体:" + livenessInfoList.get(0).getLiveness());//IR属性处理ImageInfo imageInfoGray = getGrayData(new File("C:\\Users\\DELL\\Desktop\\aa\\21.jpg"));List<FaceInfo> faceInfoListGray = new ArrayList<FaceInfo>();errorCode = faceEngine.detectFaces(imageInfoGray.getImageData(), imageInfoGray.getWidth(), imageInfoGray.getHeight(), imageInfoGray.getImageFormat(), faceInfoListGray);FunctionConfiguration configuration2 = new FunctionConfiguration();configuration2.setSupportIRLiveness(true);errorCode = faceEngine.processIr(imageInfoGray.getImageData(), imageInfoGray.getWidth(), imageInfoGray.getHeight(), imageInfoGray.getImageFormat(), faceInfoListGray, configuration2);//IR活体检测List<IrLivenessInfo> irLivenessInfo = new ArrayList<>();errorCode = faceEngine.getLivenessIr(irLivenessInfo);System.out.println("IR活体:" + irLivenessInfo.get(0).getLiveness());ImageInfoEx imageInfoEx = new ImageInfoEx();imageInfoEx.setHeight(imageInfo.getHeight());imageInfoEx.setWidth(imageInfo.getWidth());imageInfoEx.setImageFormat(imageInfo.getImageFormat());imageInfoEx.setImageDataPlanes(new byte[][]{imageInfo.getImageData()});imageInfoEx.setImageStrides(new int[]{imageInfo.getWidth() * 3});List<FaceInfo> faceInfoList1 = new ArrayList<>();errorCode = faceEngine.detectFaces(imageInfoEx, DetectModel.ASF_DETECT_MODEL_RGB, faceInfoList1);FunctionConfiguration fun = new FunctionConfiguration();fun.setSupportAge(true);errorCode = faceEngine.process(imageInfoEx, faceInfoList1, functionConfiguration);List<AgeInfo> ageInfoList1 = new ArrayList<>();int age = faceEngine.getAge(ageInfoList1);System.out.println("年龄:" + ageInfoList1.get(0).getAge());FaceFeature feature = new FaceFeature();errorCode = faceEngine.extractFaceFeature(imageInfoEx, faceInfoList1.get(0), feature);//引擎卸载errorCode = faceEngine.unInit();}
}
相关文章:
人脸识别(Java实现的)
虹软人脸识别: 虹软人脸识别的地址:虹软视觉开放平台—以免费人脸识别技术为核心的人脸识别算法开放平台 依赖包: 依赖包是从虹软开发平台下载的 在项目中引入这个依赖包 pom.xml <!-- 人脸识别 --><dependency><gr…...
Maven 依赖管理项目构建工具 教程
Maven依赖管理项目构建工具 此文档为 尚硅谷 B站maven视频学习文档,由官方文档搬运而来,仅用来当作学习笔记用途,侵删。 另:原maven教程短而精,值得推荐,下附教程链接。 atguigu 23年Maven教程 目录 文章目…...
供应链+低代码,实现数字化【共赢链】转型新策略
在深入探讨之前,让我们首先明确供应链的基本定义。供应链可以被理解为一个由采购、生产、物流配送等环节组成的网状系统,它始于原材料的采购,经过生产加工,最终通过分销和零售环节到达消费者手中。 而数字化供应链,则是…...
[力扣 Hot100]Day3 最长连续序列
题目描述 给定一个未排序的整数数组 nums ,找出数字连续的最长序列(不要求序列元素在原数组中连续)的长度。 请你设计并实现时间复杂度为 O(n) 的算法解决此问题。 出处 思路 此题可用带排序的哈希表,先构建哈希表࿰…...
【办公技巧】Word功能区灰色显示不能编辑,怎么破?
Word文档可以设置加密来保护文件禁止修改,但是在word文档中设置限制编辑功能时对它的作用是否有详细的了解呢?今天为大家介绍word限制编辑功能的作用以及忘记了限制编辑密码该如何解决。 设置限制大家应该都清楚,就是点击工具栏中的审阅 – …...
全志V853开发板原理图
本章节将对开发板几个主要的部件的原理图进行说明,方便快速上手开发板的硬件资料。 开发板硬件框图如下: 模块介绍 GPIO 分配 此表格为 V853 部分重要的 GPIO 的分配表,> 表示对IO的另外一个复用,完整的 GPIO 分配请参阅原理…...
【解决】Unity Project 面板资源显示丢失的异常问题处理
开发平台:Unity 2021.3.7f1c1 一、问题描述 在开发过程中,遭遇 Project 面板资源显示丢失、不全的问题。但 Unity Console 并未发出错误提示。 二、解决方案:删除 Library 目录 前往 “工程目录/Library” 删除内部所有文件并重打开该…...
Hyperledger Fabric Docker 方式多机部署生产网络
规划网络拓扑 3 个 orderer 节点;组织 org1 , org1 下有两个 peer 节点, peer0 和 peer1; 组织 org2 , org2 下有两个 peer 节点, peer0 和 peer1; 因为我只有 3 台虚拟机资源所以没法实现完全的多机部署,资源使用规划如下&#…...
高效降压控制器FP7132XR:为高亮度LED提供稳定可靠的电源
目录 一. FP7132概述 二. 驱动电路:FP7132 三. FP7132应用 高亮度LED作为新一代照明技术的代表,已经广泛应用于各种领域。然而,高亮度LED的工作电压较低,需要一个高效降压控制器来为其提供稳定可靠的电源。在众多降压控制器…...
Spring Boot - Application Events 的发布顺序_ApplicationEnvironmentPreparedEvent
文章目录 Pre概述Code源码分析 Pre Spring Boot - Application Events 的发布顺序_ApplicationEnvironmentPreparedEvent 概述 Spring Boot 的广播机制是基于观察者模式实现的,它允许在 Spring 应用程序中发布和监听事件。这种机制的主要目的是为了实现解耦&#…...
华为HCIE课堂笔记第十三章 IPv6地址配置
目录 第十三章 IPv6地址配置 13.1 IPv6地址无状态自动配置 13.1.1 RS和RA报文格式 13.1.2 RA的Flags字段 13.1.3 地址的生存周期 13.1.4 RA报文中前缀中的Flags 13.2 DHCPv6 13.2.1 DHCPV6的概念 13.2.2 DCHPv6的报文 第十三章 IPv6地址配置 13.1 IPv6地址无状态自动…...
计算机网络-VLAN间通信
之前复习了VLAN的概念以及几个接口类型。VLAN在二层可以实现广播域的划分,VLAN间可以实现二层通信,但是不能实现三层通信,需要借助其它方式。 一、概述 实际网络部署中一般会将不同IP地址段划分到不同的VLAN。同VLAN且同网段的PC之间可直接进…...
vue3的福音框架arco.design
前言: 在vue2于2023年底正式宣布不在维护,vue3使用越来越频繁的时刻,我们实现项目的辅助框架也越来越多。element, iview, antd 等经典框架继续风靡一时,不过也有很多好的框架,功能也强大,比如我们今天说的…...
BSP视频教程第29期:J1939协议栈CAN总线专题,源码框架,执行流程和应用实战解析,面向车通讯,充电桩,模组通信等(2024-01-08)
视频教程汇总帖:【学以致用,授人以渔】2024视频教程汇总,DSP第12期,ThreadX第9期,BSP驱动第29期,USB实战第5期,GUI实战第3期(2024-01-08) - STM32F429 - 硬汉嵌入式论坛 …...
Java lambda表达式如何自定义一个toList Collector
匿名类: package l8;import java.util.*; import java.util.function.BiConsumer; import java.util.function.BinaryOperator; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collector; import java.util.s…...
【hcie-cloud】【18】华为云Stack灾备服务介绍【容灾解决方案介绍、灾备方案架构介绍、管理组件灾备方案介绍、高阶云服务容灾简介、缩略词】【下】
文章目录 灾备方案概述、备份解决方案介绍容灾解决方案介绍华为云容灾解决方案概览云容灾服务云硬盘高可用服务 (VHA)VHA组网结构VHA逻辑组网架构VHA管理组件介绍VHA服务实现原理云服务器高可用服务(CSHA)CSHA物理组网架构CSHA逻辑组网架构CSHA服务组件间…...
linux建立软链接——以matlab为例
如果软件没有建立软连接,每次打开terminal就只是个黑黑的窗口,每次打开软件都要自己load一次,比较麻烦。 第一步: 在工作夹新建文档:project.cshrc 第二步: 在夹新建文档中写入:module laod m…...
ubuntu20固定串口名称
查看串口的详细信息 udevadm info --name/dev/ttyUSB0结果: P: /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/ttyUSB0 N: ttyUSB0 L: 0 S: serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UAR…...
扩散模型(二)——DDIM学习笔记-大白话推导
扩散模型系列: (1)扩散模型(一)——DDPM推导笔记-大白话推导 (2)扩散模型(二)——DDIM学习笔记-大白话推导 请提前关注,后续待更新,谢谢… 写在前面: (1)建议…...
【软件测试作业_TPshop商城】农业工程学院-测试需求分析与测试计划+自动化+性能+测试用例+报告软件缺陷+测试计划+单元测试+系统测试
1测试需求分析与测试计划 1.1 被测系统简介 1.2测试需求分析 1.2.1单元测试层面的测试需求分析 1.2.2系统测试层面的测试需求分析 1.3测试计划 1.31测试范围与任务 1.3.2 测试环境 1.3.3测试进度安排 测试用例的设计2 2.1单元测试层面的测试用例设计 2.2系统测试层面的测试用例…...
生成xcframework
打包 XCFramework 的方法 XCFramework 是苹果推出的一种多平台二进制分发格式,可以包含多个架构和平台的代码。打包 XCFramework 通常用于分发库或框架。 使用 Xcode 命令行工具打包 通过 xcodebuild 命令可以打包 XCFramework。确保项目已经配置好需要支持的平台…...
Java 语言特性(面试系列1)
一、面向对象编程 1. 封装(Encapsulation) 定义:将数据(属性)和操作数据的方法绑定在一起,通过访问控制符(private、protected、public)隐藏内部实现细节。示例: public …...
DeepSeek 赋能智慧能源:微电网优化调度的智能革新路径
目录 一、智慧能源微电网优化调度概述1.1 智慧能源微电网概念1.2 优化调度的重要性1.3 目前面临的挑战 二、DeepSeek 技术探秘2.1 DeepSeek 技术原理2.2 DeepSeek 独特优势2.3 DeepSeek 在 AI 领域地位 三、DeepSeek 在微电网优化调度中的应用剖析3.1 数据处理与分析3.2 预测与…...
2025年能源电力系统与流体力学国际会议 (EPSFD 2025)
2025年能源电力系统与流体力学国际会议(EPSFD 2025)将于本年度在美丽的杭州盛大召开。作为全球能源、电力系统以及流体力学领域的顶级盛会,EPSFD 2025旨在为来自世界各地的科学家、工程师和研究人员提供一个展示最新研究成果、分享实践经验及…...
Vue3 + Element Plus + TypeScript中el-transfer穿梭框组件使用详解及示例
使用详解 Element Plus 的 el-transfer 组件是一个强大的穿梭框组件,常用于在两个集合之间进行数据转移,如权限分配、数据选择等场景。下面我将详细介绍其用法并提供一个完整示例。 核心特性与用法 基本属性 v-model:绑定右侧列表的值&…...
安宝特方案丨XRSOP人员作业标准化管理平台:AR智慧点检验收套件
在选煤厂、化工厂、钢铁厂等过程生产型企业,其生产设备的运行效率和非计划停机对工业制造效益有较大影响。 随着企业自动化和智能化建设的推进,需提前预防假检、错检、漏检,推动智慧生产运维系统数据的流动和现场赋能应用。同时,…...
Linux简单的操作
ls ls 查看当前目录 ll 查看详细内容 ls -a 查看所有的内容 ls --help 查看方法文档 pwd pwd 查看当前路径 cd cd 转路径 cd .. 转上一级路径 cd 名 转换路径 …...
C++ 基础特性深度解析
目录 引言 一、命名空间(namespace) C 中的命名空间 与 C 语言的对比 二、缺省参数 C 中的缺省参数 与 C 语言的对比 三、引用(reference) C 中的引用 与 C 语言的对比 四、inline(内联函数…...
【决胜公务员考试】求职OMG——见面课测验1
2025最新版!!!6.8截至答题,大家注意呀! 博主码字不易点个关注吧,祝期末顺利~~ 1.单选题(2分) 下列说法错误的是:( B ) A.选调生属于公务员系统 B.公务员属于事业编 C.选调生有基层锻炼的要求 D…...
OpenPrompt 和直接对提示词的嵌入向量进行训练有什么区别
OpenPrompt 和直接对提示词的嵌入向量进行训练有什么区别 直接训练提示词嵌入向量的核心区别 您提到的代码: prompt_embedding = initial_embedding.clone().requires_grad_(True) optimizer = torch.optim.Adam([prompt_embedding...
