arcsoft⼈脸识别sdk使⽤⽅法(java版本)⾸先打开idea新建⼀个maven⼯程,选择File->New-&
输⼊GroupId和ArtifactId,点击Next
⼀直点击Next,最后点击Finish,⼯程就创建好了
到我们的⼯程⽂件夹
在⽂件夹src->main->java下新建包com.arcsoft
然后把从虹软官⽹下载下来的压缩包解压,解压之后是这⼀个⽂件夹,进⼊⽂件夹
有⼀个叫samplecode的⽂件夹,进去,把java⽂件拷贝到刚才新建的包com.arcsoft⾥(就是这个↓)
package com.arcsoft;
import com.arcsoft.face.*;
import com.ums.DetectMode;
import com.ums.DetectOrient;
import com.ums.ErrorInfo;
import com.ums.ImageFormat;
import com.lkit.ImageInfo;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import static com.GrayData;
import static com.RGBData;
public class FaceEngineTest {
public static void main(String[] args) {
String appId = "";
String sdkKey = "";
FaceEngine faceEngine = new FaceEngine("d:\\arcsoft-lib");
//激活引擎
int activeCode = faceEngine.activeOnline(appId, sdkKey);
if (activeCode != Value() && activeCode != ErrorInfo.MERR_ASF_Value()) {
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 != Value()) {
System.out.println("初始化引擎失败");
}
//⼈脸检测
ImageInfo imageInfo = getRGBData(new File("d:\\1.jpg"));
List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();
int detectCode = faceEngine.ImageData(), Width(), Height(), ImageFormat.CP_PAF_BGR24, faceInfo System.out.println(faceInfoList);
//特征提取
FaceFeature faceFeature = new FaceFeature();
int extractCode = ImageData(), Width(), Height(), ImageFormat.CP_PAF_BGR24, System.out.println("特征值⼤⼩:" + FeatureData().length);
//⼈脸检测2
ImageInfo imageInfo2 = getRGBData(new File("d:\\1.jpg"));
List<FaceInfo> faceInfoList2 = new ArrayList<FaceInfo>();
int detectCode2 = faceEngine.ImageData(), Width(), Height(), ImageFormat.CP_PAF_BGR24, fac System.out.println(faceInfoList);
//特征提取2
sdkFaceFeature faceFeature2 = new FaceFeature();
int extractCode2 = ImageData(), Width(), Height(), ImageFormat.CP_PAF_BGR System.out.println("特征值⼤⼩:" + FeatureData().length);
//特征⽐对
FaceFeature targetFaceFeature = new FaceFeature();
targetFaceFeature.FeatureData());
FaceFeature sourceFaceFeature = new FaceFeature();
sourceFaceFeature.FeatureData());
FaceSimilar faceSimilar = new FaceSimilar();
int compareCode = faceEnginepareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);
System.out.println("相似度:" + Score());
//⼈脸属性检测
FunctionConfiguration configuration = new FunctionConfiguration();
configuration.setSupportAge(true);
configuration.setSupportFace3dAngle(true);
configuration.setSupportGender(true);
configuration.setSupportLiveness(true);
int processCode = faceEngine.ImageData(), Width(), Height(), ImageFormat.CP_PAF_BGR24, faceInfoLis
//性别检测
List<GenderInfo> genderInfoList = new ArrayList<GenderInfo>();
int genderCode = Gender(genderInfoList);
assertEquals("性别检测失败", genderCode, Value());
System.out.println("性别:" + (0).getGender());
//年龄检测
List<AgeInfo> ageInfoList = new ArrayList<AgeInfo>();
int ageCode = Age(ageInfoList);
assertEquals("年龄检测失败", ageCode, Value());
System.out.println("年龄:" + (0).getAge());
//3D信息检测
List<Face3DAngle> face3DAngleList = new ArrayList<Face3DAngle>();
int face3dCode = Face3DAngle(face3DAngleList);
System.out.println("3D⾓度:" + (0).getPitch() + "," + (0).getRoll() + "," + (0).getYaw());
//活体检测
List<LivenessInfo> livenessInfoList = new ArrayList<LivenessInfo>();
int livenessCode = Liveness(livenessInfoList);
System.out.println("活体:" + (0).getLiveness());
//IR属性处理
ImageInfo imageInfoGray = getGrayData(new File("d:\\1.jpg"));
List<FaceInfo> faceInfoListGray = new ArrayList<FaceInfo>();
int detectCodeGray = faceEngine.ImageData(), Width(), Height(), ImageFormat.CP_PA
FunctionConfiguration configuration2 = new FunctionConfiguration();
configuration2.setSupportIRLiveness(true);
configuration2.setSupportIRLiveness(true);
int processCode2 = faceEngine.ImageData(), Width(), Height(), ImageFormat.CP_PAF_GR //IR活体检测
List<IrLivenessInfo> irLivenessInfo = new ArrayList<>();
int livenessIr = LivenessIr(irLivenessInfo);
System.out.println("IR活体:" + (0).getLiveness());
//设置活体检测参数
int paramCode = faceEngine.setLivenessParam(0.8f, 0.8f);
//获取激活⽂件信息
ActiveFileInfo activeFileInfo = new ActiveFileInfo();
int activeFileCode = ActiveFileInfo(activeFileInfo);
//引擎卸载
int unInitCode = faceEngine.unInit();
}
}
然后再退回到⼯程⽂件夹,进⼊src⽂件夹,把官⽅压缩包⾥的lib⽂件夹拷过来
这个时候回到idea,打开
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论