1首先你要到虹软的官网–注册登录
https://ai.arcsoft.com.cn/ucenter/user/userlogin
2、登录进去之后:
会让你实名认证,想使用就老老实实认证(哈哈),我这边认证过了,不贴图了。其中认证有两种:1、个人认证。2、企业认证
感觉没啥区别,可能企业审核会快一点,个人慢一点。一般2个小时都能审核通过。
3、认证完成后就可以去下载SDK了,下载之前要先创建一个应用
完成之后就能下载了!
下载完成解压就是这个样子滴:
可以把它放到想放的位置。
然后导入就可以了:这边使用的是eclipse开发工具
inport找到你的SDK导入
目录结构:
这边是主代码(我加了些注释):
package com.arcsoft;
import com.arcsoft.face.*;
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;
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;
public class FaceEngineTest {
public static void main(String[] args) {
String appId = "对应上图的APP ID";//别忘记改成你自己的
String sdkKey = "对应上图的SDKKey";//别忘记改成你自己的
FaceEngine faceEngine = new FaceEngine("d:\\arcsoft-lib");
//激活引擎
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("d:\\1.jpg"));
//人脸检测
//人脸信息类FaceInfo
List faceInfoList = new ArrayList();
//人脸检测的方法detectFaces 引擎执行类faceEngine
int detectCode = faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList);
//0代表成功
System.out.println("0是成功***"+detectCode);
//人脸位置信息
System.out.println("人脸位置信息***"+faceInfoList.get(0).getRect());
//人脸角度
System.out.println("人脸角度***"+faceInfoList.get(0).getOrient());
//人脸ID
System.out.println("人脸ID***"+faceInfoList.get(0).getFaceId());
//特征提取
//人脸特征信息类FaceFeature
FaceFeature faceFeature = new FaceFeature();
//提取人脸特征数据的方法extractFaceFeature
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("d:\\2.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 faceSimilar = new FaceSimilar();
//比对人脸特征数据获取相似度compareFaceFeature
int compareCode = faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);
System.out.println("0是成功*****"+compareCode);
System.out.println("相似度****:" + faceSimilar.getScore());
//人脸属性检测
//人脸检测功能类FunctionConfiguration
FunctionConfiguration configuration = new FunctionConfiguration();
configuration.setSupportAge(true);
configuration.setSupportFace3dAngle(true);
configuration.setSupportGender(true);
configuration.setSupportLiveness(true);
//processs人脸三维检测
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("性别:男性使0/女性是1/未知性别是-1****" + 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("d:\\1.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();
}
private static void assertEquals(String string, int ageCode, int value) {
// TODO Auto-generated method stub
}
}
虹软是没有有离线人脸库的,需要你自己提取人脸特征后把人脸特征放入到数据库,或者文件中,下面随便写的例子:用Map模拟数据库
package com.arcsoft;
import com.arcsoft.face.*;
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;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.arcsoft.face.toolkit.ImageFactory.getGrayData;
import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;
public class FaceEngineTest2 {
public static void main(String[] args) {
String appId = "对应上图的APP ID";//别忘记改成你自己的
String sdkKey = "对应上图的SDKKey";//别忘记改成你自己的
FaceEngine faceEngine = new FaceEngine("d:\\arcsoft-lib");
//激活引擎
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("d:\\5.jpg"));
//人脸检测
//人脸信息类FaceInfo
List faceInfoList = new ArrayList();
//人脸检测的方法detectFaces 引擎执行类faceEngine
int detectCode = faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList);
for (int i=0;i< faceInfoList.size();i++) {
//人脸位置信息
System.out.println("人脸位置信息***"+faceInfoList.get(i).getRect());
//人脸角度
System.out.println("人脸角度***"+faceInfoList.get(i).getOrient());
//人脸ID
System.out.println("人脸ID***"+faceInfoList.get(i).getFaceId());
}
//特征提取
//人脸特征信息类FaceFeature
FaceFeature faceFeature1 = new FaceFeature();
//提取人脸特征数据的方法extractFaceFeature
faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList.get(0), faceFeature1);
System.out.println("特征值:" +faceInfoList.get(0));
FaceFeature faceFeature2 = new FaceFeature();
//提取人脸特征数据的方法extractFaceFeature
faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList.get(1), faceFeature2);
System.out.println("特征值:" +faceInfoList.get(1));
// for(int i=0;i faceInfoList2 = new ArrayList();
faceEngine.detectFaces(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList2);
System.out.println(faceInfoList);
//第2张图人脸特征提取
FaceFeature faceFeature3 = new FaceFeature();
faceEngine.extractFaceFeature(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList2.get(0), faceFeature3);
//第3张图人脸检测
ImageInfo imageInfo3 = getRGBData(new File("d:\\3.jpg"));
List faceInfoList3= new ArrayList();
faceEngine.detectFaces(imageInfo3.getImageData(), imageInfo3.getWidth(), imageInfo3.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList3);
System.out.println(faceInfoList);
//第3张图人脸特征提取
FaceFeature faceFeature4 = new FaceFeature();
faceEngine.extractFaceFeature(imageInfo3.getImageData(), imageInfo3.getWidth(), imageInfo3.getHeight(), ImageFormat.CP_PAF_BGR24, faceInfoList3.get(0), faceFeature4);
//第1张图的2张人脸targetFaceFeature1、targetFaceFeature2
FaceFeature targetFaceFeature1 = new FaceFeature();
targetFaceFeature1.setFeatureData(faceFeature1.getFeatureData());
System.out.println("*****人脸特征******"+targetFaceFeature1);
FaceFeature targetFaceFeature2 = new FaceFeature();
targetFaceFeature2.setFeatureData(faceFeature2.getFeatureData());
System.out.println("*****人脸特征******"+targetFaceFeature2.toString());
List list=new ArrayList();
list.add(targetFaceFeature1);
list.add(targetFaceFeature2);
System.out.println("检测照片中的第一张人脸"+targetFaceFeature1);
System.out.println("检测照片中的第二张人脸"+targetFaceFeature2);
//相当于库中人脸sourceFaceFeature
FaceFeature sourceFaceFeature = new FaceFeature();
sourceFaceFeature.setFeatureData(faceFeature3.getFeatureData());
FaceFeature sourceFaceFeature2 = new FaceFeature();
sourceFaceFeature2.setFeatureData(faceFeature4.getFeatureData());
//
// List list2=new ArrayList();
// list2.add(sourceFaceFeature);
// list2.add(sourceFaceFeature2);
Map map=new HashMap();
map.put(sourceFaceFeature,"hkm");
map.put(sourceFaceFeature2,"yyx");
// System.out.println("库中第一张人脸"+sourceFaceFeature);
// System.out.println("库中第二张人脸"+sourceFaceFeature2);
//相似度信息类FaceSimilar
FaceSimilar faceSimilar = new FaceSimilar();
//比对人脸特征数据获取相似度compareFaceFeature
// faceEngine.compareFaceFeature(targetFaceFeature1, sourceFaceFeature, faceSimilar);
// System.out.println("相似度****:" + faceSimilar.getScore());
//
// FaceSimilar faceSimilar2 = new FaceSimilar();
// faceEngine.compareFaceFeature(targetFaceFeature2, sourceFaceFeature, faceSimilar2);
// System.out.println("相似度****:" + faceSimilar2.getScore());
// for(int i=0;i0.8) {
// System.out.println("相似度****:" + faceSimilar.getScore());
// }
//
// }
//
// }
for(int i=0;i0.8) {
System.out.println("相似度****:" + faceSimilar.getScore()+"是"+map.get(key));
}
}
}
//获取激活文件信息
ActiveFileInfo activeFileInfo = new ActiveFileInfo();
int activeFileCode = faceEngine.getActiveFileInfo(activeFileInfo);
//引擎卸载
int unInitCode = faceEngine.unInit();
}
private static void assertEquals(String string, int ageCode, int value) {
// TODO Auto-generated method stub
}
}