当前位置: 首页 > 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…...

多模态商品数据接口:融合图像、语音与文字的下一代商品详情体验

一、多模态商品数据接口的技术架构 &#xff08;一&#xff09;多模态数据融合引擎 跨模态语义对齐 通过Transformer架构实现图像、语音、文字的语义关联。例如&#xff0c;当用户上传一张“蓝色连衣裙”的图片时&#xff0c;接口可自动提取图像中的颜色&#xff08;RGB值&…...

PL0语法,分析器实现!

简介 PL/0 是一种简单的编程语言,通常用于教学编译原理。它的语法结构清晰,功能包括常量定义、变量声明、过程(子程序)定义以及基本的控制结构(如条件语句和循环语句)。 PL/0 语法规范 PL/0 是一种教学用的小型编程语言,由 Niklaus Wirth 设计,用于展示编译原理的核…...

UR 协作机器人「三剑客」:精密轻量担当(UR7e)、全能协作主力(UR12e)、重型任务专家(UR15)

UR协作机器人正以其卓越性能在现代制造业自动化中扮演重要角色。UR7e、UR12e和UR15通过创新技术和精准设计满足了不同行业的多样化需求。其中&#xff0c;UR15以其速度、精度及人工智能准备能力成为自动化领域的重要突破。UR7e和UR12e则在负载规格和市场定位上不断优化&#xf…...

docker 部署发现spring.profiles.active 问题

报错&#xff1a; org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property spring.profiles.active imported from location class path resource [application-test.yml] is invalid in a profile specific resource [origin: class path re…...

Python ROS2【机器人中间件框架】 简介

销量过万TEEIS德国护膝夏天用薄款 优惠券冠生园 百花蜂蜜428g 挤压瓶纯蜂蜜巨奇严选 鞋子除臭剂360ml 多芬身体磨砂膏280g健70%-75%酒精消毒棉片湿巾1418cm 80片/袋3袋大包清洁食品用消毒 优惠券AIMORNY52朵红玫瑰永生香皂花同城配送非鲜花七夕情人节生日礼物送女友 热卖妙洁棉…...

软件工程 期末复习

瀑布模型&#xff1a;计划 螺旋模型&#xff1a;风险低 原型模型: 用户反馈 喷泉模型:代码复用 高内聚 低耦合&#xff1a;模块内部功能紧密 模块之间依赖程度小 高内聚&#xff1a;指的是一个模块内部的功能应该紧密相关。换句话说&#xff0c;一个模块应当只实现单一的功能…...

jdbc查询mysql数据库时,出现id顺序错误的情况

我在repository中的查询语句如下所示&#xff0c;即传入一个List<intager>的数据&#xff0c;返回这些id的问题列表。但是由于数据库查询时ID列表的顺序与预期不一致&#xff0c;会导致返回的id是从小到大排列的&#xff0c;但我不希望这样。 Query("SELECT NEW com…...

Win系统权限提升篇UAC绕过DLL劫持未引号路径可控服务全检项目

应用场景&#xff1a; 1、常规某个机器被钓鱼后门攻击后&#xff0c;我们需要做更高权限操作或权限维持等。 2、内网域中某个机器被钓鱼后门攻击后&#xff0c;我们需要对后续内网域做安全测试。 #Win10&11-BypassUAC自动提权-MSF&UACME 为了远程执行目标的exe或者b…...

python打卡day49@浙大疏锦行

知识点回顾&#xff1a; 通道注意力模块复习空间注意力模块CBAM的定义 作业&#xff1a;尝试对今天的模型检查参数数目&#xff0c;并用tensorboard查看训练过程 一、通道注意力模块复习 & CBAM实现 import torch import torch.nn as nnclass CBAM(nn.Module):def __init__…...

二维数组 行列混淆区分 js

二维数组定义 行 row&#xff1a;是“横着的一整行” 列 column&#xff1a;是“竖着的一整列” 在 JavaScript 里访问二维数组 grid[i][j] 表示 第i行第j列的元素 let grid [[1, 2, 3], // 第0行[4, 5, 6], // 第1行[7, 8, 9] // 第2行 ];// grid[i][j] 表示 第i行第j列的…...