人脸识别(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();}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/624013.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

DeepFloyd IF:由文本生成图像的强大模型,能够绘制文字的 AI 图像工具

文章目录 一、DeepFloyd IF 简介二、DeepFloyd IF模型架构三、DeepFloyd IF模型生成流程四、DeepFloyd IF 模型定义 一、DeepFloyd IF 简介 DeepFloyd IF&#xff1a;能够绘制文字的 AI 图像工具 之前的 Stable Diffusion 和 Midjourney 都无法生成带有文字的图片&#xff0c;…

寒假冬令营(算法编程)1月12日(字符串)

题目描述&#xff08;1&#xff09; 1662. 检查两个字符串数组是否相等 . - 力扣&#xff08;LeetCode&#xff09; 给你两个字符串数组 word1 和 word2 。如果两个数组表示的字符串相同&#xff0c;返回 true &#xff1b;否则&#xff0c;返回 false 。 数组表示的字符串…

C51--摇头测距小车

摇头测距小车——舵机和超声波封装 #include "reg52.h"#include "HC04.h" #include "Delay.h" #include "sg90.h" #include "motor.h"#define MIDDLE 0 #define LEFT 1 #define RIGHT 2void main() {char dir;double di…

YOLOv8改进 | 细节涨点篇 | UNetv2提出的一种SDI多层次特征融合模块(分割高效涨点)

一、本文介绍 本问给大家带来的改进机制是UNetv2提出的一种多层次特征融合模块(SDI)其是一种用于替换Concat操作的模块,SDI模块的主要思想是通过整合编码器生成的层级特征图来增强图像中的语义信息和细节信息。该方法已在多个公开的医学图像分割数据集上进行了验证,包括皮…

【数据库原理】(27)数据库恢复

在数据库系统中&#xff0c;恢复是指在发生某种故障导致数据库数据不再正确时&#xff0c;将数据库恢复到已知正确的某一状态的过程。数据库故障可能由多种原因引起&#xff0c;包括硬件故障、软件错误、操作员失误以及恶意破坏。为了确保数据库的安全性和完整性&#xff0c;数…

多合一小程序商城系统源码:支持全平台端口 附带完整的搭建教程

现如今&#xff0c;随着移动互联网的飞速发展&#xff0c;小程序已经成为电商行业的新宠。罗峰给大家分享一款多合一小程序商城系统源码。该系统旨在为商家提供一个功能强大、易于搭建和管理的电商平台&#xff0c;帮助商家快速占领市场&#xff0c;提高品牌影响力。 以下是部…

安卓之视频智能字幕的应用场景以及各种技术优劣分析

一、文章摘要 随着技术的发展&#xff0c;智能字幕已经成为了安卓平台上一个重要的功能&#xff0c;特别是在视频播放方面。它为用户提供了一种更方便、更快捷的方式来理解视频内容&#xff0c;尤其是在多种语言环境下或者在没有声音的环境中。下面我们将详细探讨安卓平台上视频…

BP-50 开发框架使用解读

【独家框架】UWB DWM1000 开源项目框架 - 基础知识 51uwb.cn [重要更新]51uwb_base code中断更新 - 基础知识 51uwb.cn 【软件资料】BP50 套件新框架定位代码实现 - 基础知识 51uwb.cn 【开源项目】纯Python TWR算法UWB上位机 - 基础知识 51uwb.cn 上位机软件通信协议更改说明 …

【打卡】牛客网:BM88 判断是否为回文字符串

我写的&#xff1a; 其实不用考虑奇数长度还是偶数长度。 class Solution { public:/*** 代码中的类名、方法名、参数名已经指定&#xff0c;请勿修改&#xff0c;直接返回方法规定的值即可** * param str string字符串 待判断的字符串* return bool布尔型*/bool judge(strin…

day08

回顾 1.选择排序原理: 找到最小值的下标&#xff0c;交换 2.冒泡排序原理: 比较相邻的两个元素&#xff0c;把最小值放到左边。第一次比较的时候最大值放到最右边了&#xff0c;以此类推今天的内容 1类和对象 2.类和对象内存 3.构造方法 1.从生活的角度区理解面向对象开发 有两…

C program to check little vs. big endian

void main() {int n 1;// little endian if trueif(*(char *)&n 1)printf("This is little endian\n");elseprintf("This is big endian\n"); }Suppose we are on a 32-bit machine. And char type is 8 bits

如何配置mybatisplus基础环境?

1.在pom文件&#xff08;都加上吧&#xff0c;以防万一&#xff09; 2.若当初有mybatis的依赖&#xff0c;要删除 3.在Mapper接口加上"extends BaseMapper<实体类型>" 4.更改yml文件内容 别名扫描包&#xff1a;是指实体类型 5.添加"extends ServiceIm…

Python中英文时间转换

&#x1f345; 写在前面 &#x1f468;‍&#x1f393; 博主介绍&#xff1a;大家好&#xff0c;这里是hyk写算法了吗&#xff0c;一枚致力于学习算法和人工智能领域的小菜鸟。 &#x1f50e;个人主页&#xff1a;主页链接&#xff08;欢迎各位大佬光临指导&#xff09; ⭐️近…

互联网行业的高水平简历怎么写?(附模板)

HR浏览一份简历也就25秒左右&#xff0c;如果你连「好简历」都没有&#xff0c;怎么能找到好工作呢&#xff1f; 如果你不懂得如何在简历上展示自己&#xff0c;或者觉得怎么改简历都不出彩&#xff0c;那请你一定仔细读完。 互联网运营个人简历范文> 男 22 本科 AI简历…

Java智能导诊系统 (3D人体导医)源码

智能导诊是一种利用人工智能技术来帮助患者进行自助问询及挂号服务的系统。通过智能导诊系统&#xff0c;患者可以输入自身疾病的症状表现&#xff0c;或选择身体部位&#xff0c;在系统的多维度计算下&#xff0c;系统会根据患者提供的信息精准推荐科室&#xff0c;并引导患者…

DataX数据同步(全量)

1. DataX简介 1.1 DataX概述 DataX 是阿里巴巴开源的一个异构数据源离线同步工具&#xff0c;致力于实现包括关系型数据库(MySQL、Oracle等)、HDFS、Hive、ODPS、HBase、FTP等各种异构数据源之间稳定高效的数据同步功能。 源码地址&#xff1a;https://github.com/alibaba/Dat…

Elasticsearch:聊天机器人教程(一)

在本教程中&#xff0c;你将构建一个大型语言模型 (LLM) 聊天机器人&#xff0c;该机器人使用称为检索增强生成 (RAG) 的模式。 使用 RAG 构建的聊天机器人可以克服 ChatGPT 等通用会话模型所具有的一些限制。 特别是&#xff0c;他们能够讨论和回答以下问题&#xff1a; 你的…

构建基于RHEL9系列(CentOS9,AlmaLinux9,RockyLinux9等)的支持63个常见模块的PHP8.1.20的RPM包

本文适用&#xff1a;rhel9系列&#xff0c;或同类系统(CentOS9,AlmaLinux9,RockyLinux9等) 文档形成时期&#xff1a;2023年 因系统版本不同&#xff0c;构建部署应略有差异&#xff0c;但本文未做细分&#xff0c;对稍有经验者应不存在明显障碍。 因软件世界之复杂和个人能力…

测试学习——答疑

1、什么是软件测试&#xff1f; 一个产品质量好&#xff0c;用户的使用感受佳&#xff0c;用户才愿意为此付费&#xff0c;这样企业才会获取收益&#xff0c;如果一个产品bug太多的话&#xff0c;那用户就不会买账。所以软件测试就是对产品进行测试&#xff0c;提高测试质量&am…

LLM之RAG理论(五)| 使用知识图谱增强RAG

知识图谱&#xff08;KG&#xff09;或任何图都包括节点和边&#xff0c;其中每个节点表示一个概念&#xff0c;每个边表示一对概念之间的关系。本文介绍一种将任何文本语料库转换为知识图谱的技术&#xff0c;本文演示的知识图谱可以替换其他专业知识图谱。 一、知识图谱 知识…