当前位置: 首页 > news >正文

springboot虹软人脸识别集成

准备工作

在这里插入图片描述
虹软开放平台中创建一个新的应用 虹软开发平台【点我跳转】

开始上代码

基本配置

在这里插入图片描述
将下载的jar包放到src同级目录下

 <!--        虹软--><dependency><groupId>com.arcsoft.face</groupId><artifactId>arcsoft-sdk-face</artifactId><version>3.0.0.0</version><scope>system</scope><systemPath>${basedir}/libs/arcsoft-sdk-face-3.0.0.0.jar</systemPath></dependency><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><!-- 加入下面这一行 --><includeSystemScope>true</includeSystemScope></configuration><version>2.3.4.RELEASE</version><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin>

配置类初始化

@Data
@Configuration
@ConfigurationProperties(prefix = "arcsoft")
public class ArcSoftConfig {private String appid;// win平台sdk 此处为了开发时调试 生产一般linux 不需要此设置private String winsdkkey;// linux平台sdk private String linuxsdkkey;// dll/so库路径private String libpath;/*** 装载FaceEngine交给spring托管* * @return*/@Beanpublic FaceEngine faceEngine() {String sdkkey = "";String os = System.getProperty("os.name");if (os.toLowerCase().startsWith("win")) {sdkkey = winsdkkey;String projectPath = System.getProperty("user.dir");libpath = projectPath + "\\libs\\WIN64";} else {sdkkey = linuxsdkkey;}FaceEngine faceEngine = new FaceEngine(libpath);int errorCode = faceEngine.activeOnline(appid, sdkkey);if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {throw new RuntimeException("引擎注册失败");}EngineConfiguration engineConfiguration = getFaceEngineConfiguration();// 初始化引擎errorCode = faceEngine.init(engineConfiguration);if (errorCode != ErrorInfo.MOK.getValue()) {throw new RuntimeException("初始化引擎失败");}return faceEngine;}/*** 初始化引擎配置* * @return*/private EngineConfiguration getFaceEngineConfiguration() {EngineConfiguration engineConfiguration = new EngineConfiguration();// 配置引擎模式if ("IMAGE".equals(EngineConfigurationProperty.DETECT_MODE)) {engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);} else {engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_VIDEO);}// 配置人脸角度 全角度 ASF_OP_ALL_OUT 不够准确且检测速度慢switch (EngineConfigurationProperty.DETECT_FACE_ORIENT_PRIORITY) {case "ASF_OP_0_ONLY":engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_0_ONLY);break;case "ASF_OP_90_ONLY":engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_90_ONLY);break;case "ASF_OP_270_ONLY":engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_270_ONLY);break;case "ASF_OP_180_ONLY":engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_180_ONLY);break;case "ASF_OP_ALL_OUT":engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_ALL_OUT);break;default:engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_ALL_OUT);}// 设置识别的最小人脸比engineConfiguration.setDetectFaceScaleVal(EngineConfigurationProperty.DETECT_FACE_SCALE);engineConfiguration.setDetectFaceMaxNum(EngineConfigurationProperty.DETECT_FACE_MAX_NUM);// 功能配置initFuncConfiguration(engineConfiguration);return engineConfiguration;}/*** 功能配置* * @param engineConfiguration*/private void initFuncConfiguration(EngineConfiguration engineConfiguration) {FunctionConfiguration functionConfiguration = new FunctionConfiguration();// 是否支持年龄检测functionConfiguration.setSupportAge(FunConfigurationProperty.SUPPORT_AGE);// 是否支持3d 检测functionConfiguration.setSupportFace3dAngle(FunConfigurationProperty.SUPPORT_FACE_3D_ANGLE);// 是否支持人脸检测functionConfiguration.setSupportFaceDetect(FunConfigurationProperty.SUPPORT_FACE_DETECT);// 是否支持人脸识别functionConfiguration.setSupportFaceRecognition(FunConfigurationProperty.SUPPORT_FACE_RECOGNITION);// 是否支持性别检测functionConfiguration.setSupportGender(FunConfigurationProperty.SUPPORT_GENDER);// 是否支持活体检测functionConfiguration.setSupportLiveness(FunConfigurationProperty.SUPPORT_LIVENESS);// 是否支持IR活体检测functionConfiguration.setSupportIRLiveness(FunConfigurationProperty.SUPPORT_IR_LIVENESS);engineConfiguration.setFunctionConfiguration(functionConfiguration);}
}

yml配置文件
在这里插入图片描述

其他配置

引擎类

public class EngineConfigurationProperty {/*** 引擎模式*/public static final String DETECT_MODE = "IMAGE";/*** 配置人脸角度*/public static final String DETECT_FACE_ORIENT_PRIORITY = "ASF_OP_ALL_OUT";/*** 设置识别的最小人脸比*/public static final Integer DETECT_FACE_SCALE = 32;/*** 最大检测人脸数*/public static final Integer DETECT_FACE_MAX_NUM = 8;
}

功能类

public class FunConfigurationProperty {/*** 是否支持3d 检测*/public static final Boolean SUPPORT_FACE_3D_ANGLE = true;/*** 是否支持人脸检测*/public static final Boolean SUPPORT_FACE_DETECT = true;/*** 是否支持人脸识别*/public static final Boolean SUPPORT_FACE_RECOGNITION = true;/*** 性别检测*/public static final Boolean SUPPORT_GENDER = true;/*** 年龄检测*/public static final Boolean SUPPORT_AGE = true;/*** 是否支持活体检测*/public static final Boolean SUPPORT_LIVENESS = true;/*** 是否至此IR活体检测*/public static final Boolean SUPPORT_IR_LIVENESS = true;
}

人脸相关方法

@Component
public class ArcFaceMothodUtils {@Autowiredprivate FaceEngine faceEngine;/*** 人脸检测*/public List<FaceInfo> detectFace(ImageInfoEx imageInfoEx) {if (imageInfoEx == null) {return null;}List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();int i = faceEngine.detectFaces(imageInfoEx, DetectModel.ASF_DETECT_MODEL_RGB, faceInfoList);checkEngineResult(i, ErrorInfo.MOK.getValue(), "人脸检测失败");return faceInfoList;}/*** 特征提取*/public FaceFeature extractFaceFeature(List<FaceInfo> faceInfoList, ImageInfoEx imageInfoEx) {if (faceInfoList == null || imageInfoEx == null) {return null;}FaceFeature faceFeature = new FaceFeature();int i = faceEngine.extractFaceFeature(imageInfoEx, faceInfoList.get(0), faceFeature);checkEngineResult(i, ErrorInfo.MOK.getValue(), "人脸特征提取失败");return faceFeature;}/*** 特征比对*/public FaceSimilar compareFaceFeature(FaceFeature target, FaceFeature source, CompareModel compareModel) {FaceSimilar faceSimilar = new FaceSimilar();int i = faceEngine.compareFaceFeature(target, source, compareModel, faceSimilar);checkEngineResult(i, ErrorInfo.MOK.getValue(), "人脸特征对比失败");return faceSimilar;}/*** 错误检测*/private void checkEngineResult(int errorCode, int sourceCode, String errMsg) {if (errorCode != sourceCode) {throw new RuntimeException(errMsg);}}
}

虹软图片处理工具类

@Slf4j
public class ArcfaceUtils {/*** 处理 File 的图片流* * @param img* @return*/public static ImageInfoMeta packImageInfoEx(File img) {ImageInfo imageInfo = ImageFactory.getRGBData(img);return packImageInfoMeta(imageInfo);}/*** 处理 byte[] 的图片流* * @param img* @return*/public static ImageInfoMeta packImageInfoMeta(byte[] img) {ImageInfo imageInfo = ImageFactory.getRGBData(img);return packImageInfoMeta(imageInfo);}/*** 处理 InpuStream 的图片流* * @param img* @return*/public static ImageInfoMeta packImageInfoMeta(InputStream img) {ImageInfo imageInfo = ImageFactory.getRGBData(img);return packImageInfoMeta(imageInfo);}/*** 处理 网络图片 的图片流** @param path* @return*/public static ImageInfoMeta packImageInfoURL(String path) {try {InputStream inputStream = getImageInputStream(path);ImageInfo imageInfo = ImageFactory.getRGBData(inputStream);return packImageInfoMeta(imageInfo);} catch (Exception e) {log.error("处理网络图片处理失败", e);}return null;}/*** 处理 base图片 的图片流** @param base64* @return*/public static ImageInfoMeta packImageInfoBase64(String base64) {try {ImageInfo imageInfo = ImageFactory.getRGBData(removeBase64Prefix(base64));return packImageInfoMeta(imageInfo);} catch (Exception e) {log.error("处理网络图片处理失败", e);}return null;}public static byte[] removeBase64Prefix(String base64String) {if (base64String.startsWith("data:image/jpeg;base64,")) {base64String = base64String.replace("data:image/jpeg;base64,", "");}if (base64String.startsWith("data:image/png;base64,")) {base64String = base64String.replace("data:image/png;base64,", "");}return Base64.getDecoder().decode(base64String);}public static InputStream getImageInputStream(String imageUrl) throws Exception {URL url = new URL(imageUrl);URLConnection connection = url.openConnection();return connection.getInputStream();}/*** 打包生成 ImageInfoMeta* * @param imageInfo* @return*/private static ImageInfoMeta packImageInfoMeta(ImageInfo imageInfo) {ImageInfoMeta imageInfoMeta = new ImageInfoMeta(imageInfo);return imageInfoMeta;}/*** 对imageInfo 和 imageInfoEx 的打包对象* * @return*/@Datapublic static class ImageInfoMeta {private ImageInfo imageInfo;private ImageInfoEx imageInfoEx;public ImageInfoMeta(ImageInfo imageInfo) {this.imageInfo = imageInfo;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 });}}}

实际业务使用

        // 开始使用虹软人脸识别ArcfaceUtils.ImageInfoMeta imageInfoMeta1 = ArcfaceUtils.packImageInfoURL(photo);if (null == imageInfoMeta1) {throw new ValidatorException("您的人脸信息在系统内已失效请重新录入");}// 系统的人脸库信息List<FaceInfo> faceInfo1 = arcFaceMothodUtils.detectFace(imageInfoMeta1.getImageInfoEx());FaceFeature faceFeature1 = arcFaceMothodUtils.extractFaceFeature(faceInfo1, imageInfoMeta1.getImageInfoEx());// 当前需要对比的人脸ArcfaceUtils.ImageInfoMeta imageInfoMeta2 = ArcfaceUtils.packImageInfoBase64(dto.getFacePic());if (null == imageInfoMeta2) {throw new ValidatorException("您的人脸信息人脸特征提取失败,请重试");}List<FaceInfo> faceInfo2 = arcFaceMothodUtils.detectFace(imageInfoMeta2.getImageInfoEx());FaceFeature faceFeature2 = arcFaceMothodUtils.extractFaceFeature(faceInfo2, imageInfoMeta2.getImageInfoEx());FaceSimilar faceSimilar = arcFaceMothodUtils.compareFaceFeature(faceFeature1, faceFeature2,CompareModel.LIFE_PHOTO);// 相似度float score = faceSimilar.getScore();log.info("当前匹配的身份证信息【{}】,相似度:{}", dto.getUserId(), score);

希望对大家能够有所帮助 仅作为个人笔记使用

相关文章:

springboot虹软人脸识别集成

准备工作 虹软开放平台中创建一个新的应用 虹软开发平台【点我跳转】 开始上代码 基本配置 将下载的jar包放到src同级目录下 <!-- 虹软--><dependency><groupId>com.arcsoft.face</groupId><artifactId>arcsoft-sdk-face</artifactI…...

Element+vue3.0 tabel合并单元格span-method

Elementvue3.0 tabel合并单元格 span-method :span-method"objectSpanMethod"详解&#xff1a; 在 objectSpanMethod 方法中&#xff0c;rowspan 和 colspan 的值通常用来定义单元格的行跨度和列跨度。 一般来说&#xff0c;rowspan 和 colspan 的值应该是大于等于…...

Python学习笔记第七十九天(OpenCV轨迹栏)

Python学习笔记第七十九天 OpenCV轨迹栏cv.createTrackbarcv.getTrackbarPos两者合并运用 后记 OpenCV轨迹栏 cv.getTrackbarPos 和 cv.createTrackbar 是 OpenCV 库中用于创建和获取跟踪条位置的函数。这些函数通常用于在视频处理或图像处理应用程序中创建用户界面&#xff0…...

uniapp自定义顶部导航并解决打包成apk后getMenuButtonBoundingClientRect方法失效问题

需求&#xff1a;要在app上的顶部导航提示哪里添加一些东西进去&#xff0c;用uniapp自带的肯定不行啊&#xff0c;所以自定义了所有的页面的顶部导航&#xff0c;之后自定义后用手机调试发现 uni.getMenuButtonBoundingClientRect()这个方法的top获取不到....网上找了很多种方…...

C++入门【26-C++ Null 指针】

在变量声明的时候&#xff0c;如果没有确切的地址可以赋值&#xff0c;为指针变量赋一个 NULL 值是一个良好的编程习惯。赋为 NULL 值的指针被称为空指针。 NULL 指针是一个定义在标准库中的值为零的常量。请看下面的程序&#xff1a; 实例 #include <iostream> using…...

Linux第14步_安装FTP服务器

安装“vim编辑器”后&#xff0c;我们紧接着“安装FTP服务器”。 1、在安装前&#xff0c;要检查虚拟机可以上网&#xff0c;否则可能会导致安装失败。 2、在虚拟机界面右击鼠标&#xff0c;弹出下面的对话框 3、点击“打开终端(E)”&#xff0c;得到下面的界面 &#xff1a;…...

Linux截图方法推荐

因为经常会遇到以图为证的情况&#xff0c;而办公设备基本都是linux,所以汇总一下常见的linux截图方式。 1&#xff1a;在 Linux 中系统集成的截图的默认方式 你想要截取整个屏幕&#xff1f;屏幕中的某个区域&#xff1f;某个特定的窗口&#xff1f; 如果只需要获取一张屏幕…...

在Gitee上维护Erpnext源

在Gitee上维护Erpnext源 官方的frappe和erpnext地址: GitHub - frappe/frappe: Low code web framework for real world applications, in Python and Javascript GitHub - frappe/erpnext: Free and Open Source Enterprise Resource Planning (ERP) 1, 仓库地址输入frappe的官…...

2024.1.9 基于 Jedis 通过 Java 客户端连接 Redis 服务器

目录 引言 RESP 协议 Redis 通信过程 实现步骤 步骤一 步骤二 步骤三 步骤四 引言 在 Redis 命令行客户端中手敲命令并不是我们日常开发中的主要形式而更多的时候是使用 Redis 的 API 来实现定制化的 Redis 客户端程序&#xff0c;进而操作 Redis 服务器即使用程序来操…...

软件测试|SQL ORDER BY排序利器使用

简介 在SQL查询语言中&#xff0c;ORDER BY子句是一项重要的功能&#xff0c;它允许我们按照指定的列或表达式对查询结果进行排序。本文将详细介绍SQL ORDER BY子句的用法、常见排序方式以及在实际应用中的应用场景。 ORDER BY子句 SQL是一种用于管理和操作关系型数据库的强…...

苹果手机IOS软件应用IPA砸壳包提取完整教程

我们有很多小伙伴可能想要获取到苹果手机软件的安装包但又不知该如何获取&#xff0c;本文就教你如何获取到IOS软件的IPA砸壳包 首先我们需要准备一台越狱的苹果IOS设备&#xff0c;如果不知如何越狱的可以参考这篇苹果手机越狱教程&#xff1a;https://www.hereitis.cn/artic…...

「 网络安全术语解读 」内容安全策略CSP详解

引言&#xff1a;什么是CSP&#xff0c;它为什么可以防御一些常见的网络攻击&#xff0c;比如XSS攻击&#xff0c;具体原理是什么&#xff1f;以及如何绕过CSP&#xff1f; 1. CSP定义 CSP&#xff08;Content Security Policy&#xff0c;内容安全策略&#xff09;是一种网络…...

Docker与微服务实战(基础篇)

Docker与微服务实战&#xff08;基础篇&#xff09; 1、Docker简介2、Docker安装步骤1.Centos7及以上的版本2.卸载旧版本3.yum安装gcc相关4.安装需要的软件包5.设置stable镜像仓库【国内aliyun】6.更新yum软件包索引--以后安装更快捷7.安装Docker-Ce8.启动Docker9.测试10.卸载1…...

「实用分享」如何用Telerik UI组件创建可扩展的企业级WPF应用?

Telerik UI for WPF拥有超过100个控件来创建美观、高性能的桌面应用程序&#xff0c;同时还能快速构建企业级办公WPF应用程序。UI for WPF支持MVVM、触摸等&#xff0c;创建的应用程序可靠且结构良好&#xff0c;非常容易维护&#xff0c;其直观的API将无缝地集成Visual Studio…...

【Docker基础三】Docker安装Redis

下载镜像 根据自己需要下载指定版本镜像&#xff0c;所有版本看这&#xff1a;Index of /releases/ (redis.io) 或 https://hub.docker.com/_/redis # 下载指定版本redis镜像 docker pull redis:7.2.0 # 查看镜像是否下载成功 docker images 创建挂载目录 # 宿主机上创建挂…...

【Flink精讲】Flink数据延迟处理

面试题&#xff1a;Flink数据延迟怎么处理&#xff1f; 将迟到数据直接丢弃【默认方案】将迟到数据收集起来另外处理&#xff08;旁路输出&#xff09;重新激活已经关闭的窗口并重新计算以修正结果&#xff08;Lateness&#xff09; Flink数据延迟处理方案 用一个案例说明三…...

vue项目心得(复盘)

在编写项目过程中&#xff0c;首先是接手一个需要优化的项目&#xff0c;需要查看vue.config.js环境配置地址&#xff0c;确认好测试地址后进行开发&#xff0c;目前在开发过程中&#xff0c;遇到的最多的问题就是关于组件间的&#xff0c; 组件间传值 1、父组件异步传值&…...

Linux——firewalld防火墙(一)

一、Linux防火墙基础 Linux 的防火墙体系主要工作在网络层.针对TCP/P数据包实时过滤和限制.属于典型的包过滤防火墙&#xff08;或称为网络层防火墙)。Linux系统的防火墙体系基于内核编码实现&#xff0e;具有非常稳定的性能和高效率,也因此获得广泛的应用.在CentOS 7系统中几种…...

JMeter之Windows安装

JMeter之Windows安装 一、安装JDK二、安装JMeter1、下载JMeter2、配置环境变量3、验证JMeter 三、扩展知识1、汉化 一、安装JDK 略 二、安装JMeter 1、下载JMeter 官网地址&#xff1a;https://jmeter.apache.org/download_jmeter.cgi 放到本地目录下 2、配置环境变量 变量…...

用通俗易懂的方式讲解:大模型 RAG 在 LangChain 中的应用实战

Retrieval-Augmented Generation&#xff08;RAG&#xff09;是一种强大的技术&#xff0c;能够提高大型语言模型&#xff08;LLM&#xff09;的性能&#xff0c;使其能够从外部知识源中检索信息以生成更准确、具有上下文的回答。 本文将详细介绍 RAG 在 LangChain 中的应用&a…...

国防科技大学计算机基础课程笔记02信息编码

1.机内码和国标码 国标码就是我们非常熟悉的这个GB2312,但是因为都是16进制&#xff0c;因此这个了16进制的数据既可以翻译成为这个机器码&#xff0c;也可以翻译成为这个国标码&#xff0c;所以这个时候很容易会出现这个歧义的情况&#xff1b; 因此&#xff0c;我们的这个国…...

Prompt Tuning、P-Tuning、Prefix Tuning的区别

一、Prompt Tuning、P-Tuning、Prefix Tuning的区别 1. Prompt Tuning(提示调优) 核心思想:固定预训练模型参数,仅学习额外的连续提示向量(通常是嵌入层的一部分)。实现方式:在输入文本前添加可训练的连续向量(软提示),模型只更新这些提示参数。优势:参数量少(仅提…...

脑机新手指南(八):OpenBCI_GUI:从环境搭建到数据可视化(下)

一、数据处理与分析实战 &#xff08;一&#xff09;实时滤波与参数调整 基础滤波操作 60Hz 工频滤波&#xff1a;勾选界面右侧 “60Hz” 复选框&#xff0c;可有效抑制电网干扰&#xff08;适用于北美地区&#xff0c;欧洲用户可调整为 50Hz&#xff09;。 平滑处理&…...

可靠性+灵活性:电力载波技术在楼宇自控中的核心价值

可靠性灵活性&#xff1a;电力载波技术在楼宇自控中的核心价值 在智能楼宇的自动化控制中&#xff0c;电力载波技术&#xff08;PLC&#xff09;凭借其独特的优势&#xff0c;正成为构建高效、稳定、灵活系统的核心解决方案。它利用现有电力线路传输数据&#xff0c;无需额外布…...

Nginx server_name 配置说明

Nginx 是一个高性能的反向代理和负载均衡服务器&#xff0c;其核心配置之一是 server 块中的 server_name 指令。server_name 决定了 Nginx 如何根据客户端请求的 Host 头匹配对应的虚拟主机&#xff08;Virtual Host&#xff09;。 1. 简介 Nginx 使用 server_name 指令来确定…...

CRMEB 框架中 PHP 上传扩展开发:涵盖本地上传及阿里云 OSS、腾讯云 COS、七牛云

目前已有本地上传、阿里云OSS上传、腾讯云COS上传、七牛云上传扩展 扩展入口文件 文件目录 crmeb\services\upload\Upload.php namespace crmeb\services\upload;use crmeb\basic\BaseManager; use think\facade\Config;/*** Class Upload* package crmeb\services\upload* …...

网络编程(UDP编程)

思维导图 UDP基础编程&#xff08;单播&#xff09; 1.流程图 服务器&#xff1a;短信的接收方 创建套接字 (socket)-----------------------------------------》有手机指定网络信息-----------------------------------------------》有号码绑定套接字 (bind)--------------…...

使用 SymPy 进行向量和矩阵的高级操作

在科学计算和工程领域&#xff0c;向量和矩阵操作是解决问题的核心技能之一。Python 的 SymPy 库提供了强大的符号计算功能&#xff0c;能够高效地处理向量和矩阵的各种操作。本文将深入探讨如何使用 SymPy 进行向量和矩阵的创建、合并以及维度拓展等操作&#xff0c;并通过具体…...

20个超级好用的 CSS 动画库

分享 20 个最佳 CSS 动画库。 它们中的大多数将生成纯 CSS 代码&#xff0c;而不需要任何外部库。 1.Animate.css 一个开箱即用型的跨浏览器动画库&#xff0c;可供你在项目中使用。 2.Magic Animations CSS3 一组简单的动画&#xff0c;可以包含在你的网页或应用项目中。 3.An…...

Caliper 配置文件解析:fisco-bcos.json

config.yaml 文件 config.yaml 是 Caliper 的主配置文件,通常包含以下内容: test:name: fisco-bcos-test # 测试名称description: Performance test of FISCO-BCOS # 测试描述workers:type: local # 工作进程类型number: 5 # 工作进程数量monitor:type: - docker- pro…...