Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hiwepy/arcface-spring-boot-starter

基于虹软人脸识别整合的SDK实现
https://github.com/hiwepy/arcface-spring-boot-starter

Last synced: 23 days ago
JSON representation

基于虹软人脸识别整合的SDK实现

Awesome Lists containing this project

README

        

# arcface-spring-boot-starter

#### 组件简介

> 基于 [虹软 - 视觉开放平台](https://ai.arcsoft.com.cn/index.html) 人脸识别SDK实现的人脸识别整合

#### 使用说明

##### 1、发布SDK到自己的 Maven私服(`请下载新版本`)

```shell
mvn deploy:deploy-file -DgroupId=com.baidu.aip -DartifactId=java-sdk -Dversion=4.11.1 -Dpackaging=jar -Dfile=D:\aip-java-sdk-4.11.1.jar -Durl=http://127.0.0.1:8082/nexus/content/repositories/releases/ -DrepositoryId=nexus-releases
```

##### 2、Spring Boot 项目添加 Maven 依赖

``` xml

com.github.hiwepy
arcface-spring-boot-starter
${project.version}

```

##### 2、在`application.yml`文件中增加如下配置

```yaml
#################################################################################################
### 虹软人脸识别 配置:
#################################################################################################
arcface:
enabled: true
app-id: xx
sdk-key: xxx
detect-mode: asf_detect_mode_image
detect-face-max-num: 1
detect-face-orient-priority: asf_op_0_only
detect-face-scale-val: 1
function-configuration:
support-age: true
support-face-detect: true
support-face-recognition: true
support-face3d-angle: true
support-gender: true
support-iRLiveness: true
support-liveness: true
lib-path: usr\libs
pool2:
max-idle: 5
max-total: 10
test-on-borrow: true
test-on-create: true
test-on-return: false
test-while-idle: false
```

##### 3、使用示例


```java

import static com.arcsoft.face.toolkit.ImageFactory.getGrayData;
import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;
import static org.junit.Assert.assertEquals;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.arcsoft.face.ActiveFileInfo;
import com.arcsoft.face.AgeInfo;
import com.arcsoft.face.EngineConfiguration;
import com.arcsoft.face.Face3DAngle;
import com.arcsoft.face.FaceEngine;
import com.arcsoft.face.FaceFeature;
import com.arcsoft.face.FaceInfo;
import com.arcsoft.face.FaceSimilar;
import com.arcsoft.face.FunctionConfiguration;
import com.arcsoft.face.GenderInfo;
import com.arcsoft.face.IrLivenessInfo;
import com.arcsoft.face.LivenessInfo;
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.ImageInfo;

public class FaceEngineTest {

public static void main(String[] args) {

String appId = "";
String sdkKey = "";

FaceEngine faceEngine = new FaceEngine();
//激活引擎
int activeCode = faceEngine.activeOnline(appId, sdkKey);

if (activeCode != ErrorInfo.MOK.getValue() && activeCode != 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_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()) {
System.out.println("初始化引擎失败");
}

//人脸检测
ImageInfo imageInfo = getRGBData(new File("f:\\timg.jpg"));
List faceInfoList = new ArrayList();
int detectCode = faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList);
System.out.println(faceInfoList);

//特征提取
FaceFeature faceFeature = new FaceFeature();
int extractCode = faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList.get(0), faceFeature);
System.out.println("特征值大小:" + faceFeature.getFeatureData().length);

//人脸检测2
ImageInfo imageInfo2 = getRGBData(new File("f:\\timg.jpg"));
List faceInfoList2 = new ArrayList();
int detectCode2 = faceEngine.detectFaces(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList2);
System.out.println(faceInfoList);

//特征提取2
FaceFeature faceFeature2 = new FaceFeature();
int extractCode2 = faceEngine.extractFaceFeature(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList2.get(0), faceFeature2);
System.out.println("特征值大小:" + faceFeature.getFeatureData().length);

//特征比对
FaceFeature targetFaceFeature = new FaceFeature();
targetFaceFeature.setFeatureData(faceFeature.getFeatureData());
FaceFeature sourceFaceFeature = new FaceFeature();
sourceFaceFeature.setFeatureData(faceFeature2.getFeatureData());
FaceSimilar faceSimilar = new FaceSimilar();
int compareCode = faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);
System.out.println("相似度:" + faceSimilar.getScore());

//人脸属性检测
FunctionConfiguration configuration = new FunctionConfiguration();
configuration.setSupportAge(true);
configuration.setSupportFace3dAngle(true);
configuration.setSupportGender(true);
configuration.setSupportLiveness(true);
int processCode = faceEngine.process(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList, configuration);

//性别检测
List genderInfoList = new ArrayList();
int genderCode = faceEngine.getGender(genderInfoList);
assertEquals("性别检测失败", genderCode, ErrorInfo.MOK.getValue());
System.out.println("性别:" + genderInfoList.get(0).getGender());

//年龄检测
List ageInfoList = new ArrayList();
int ageCode = faceEngine.getAge(ageInfoList);
assertEquals("年龄检测失败", ageCode, ErrorInfo.MOK.getValue());
System.out.println("年龄:" + ageInfoList.get(0).getAge());

//3D信息检测
List face3DAngleList = new ArrayList();
int face3dCode = faceEngine.getFace3DAngle(face3DAngleList);
System.out.println("3D角度:" + face3DAngleList.get(0).getPitch() + "," + face3DAngleList.get(0).getRoll() + "," + face3DAngleList.get(0).getYaw());

//活体检测
List livenessInfoList = new ArrayList();
int livenessCode = faceEngine.getLiveness(livenessInfoList);
System.out.println("活体:" + livenessInfoList.get(0).getLiveness());

//IR属性处理
ImageInfo imageInfoGray = getGrayData(new File("f:\\timg.jpg"));
List faceInfoListGray = new ArrayList();
int detectCodeGray = faceEngine.detectFaces(imageInfoGray.getImageData(), imageInfoGray.getWidth(), imageInfoGray.getHeight(), ImageFormat.CP_PAF_GRAY, faceInfoListGray);

FunctionConfiguration configuration2 = new FunctionConfiguration();
configuration2.setSupportIRLiveness(true);
int processCode2 = faceEngine.processIr(imageInfoGray.getImageData(), imageInfoGray.getWidth(), imageInfoGray.getHeight(), ImageFormat.CP_PAF_GRAY, faceInfoListGray, configuration2);

//IR活体检测
List irLivenessInfo = new ArrayList<>();
int livenessIr = faceEngine.getLivenessIr(irLivenessInfo);
System.out.println("IR活体:" + irLivenessInfo.get(0).getLiveness());

//设置活体检测参数
int paramCode = faceEngine.setLivenessParam(0.8f, 0.8f);

//获取激活文件信息
ActiveFileInfo activeFileInfo = new ActiveFileInfo();
int activeFileCode = faceEngine.getActiveFileInfo(activeFileInfo);

//引擎卸载
int unInitCode = faceEngine.unInit();
}
}
```

## Jeebiz 技术社区

Jeebiz 技术社区 **微信公共号**、**小程序**,欢迎关注反馈意见和一起交流,关注公众号回复「Jeebiz」拉你入群。

|公共号|小程序|
|---|---|
| ![](https://raw.githubusercontent.com/hiwepy/static/main/images/qrcode_for_gh_1d965ea2dfd1_344.jpg)| ![](https://raw.githubusercontent.com/hiwepy/static/main/images/gh_09d7d00da63e_344.jpg)|