虹软人脸识别技术

首先我们在官网下载appId 和sdkkey

https://ai.arcsoft.com.cn/ucenter/resource/build/index.html#/index

进去之后先注册账号这个一年内没有次数限制,到期只需要重新换一下appId 和sdkkey即可,在这个页面选择免费SDK右下角这个

这个过程中有个应用,自己起名字就可以,建议取成idea、java之类

注册好了就会有appId 和sdkkey如下图

点击下载SDK我们会得到对应的压缩包,打开之后samplecode文件夹里面有一个FaceEngineTest 的文件夹(测试代码)

我们在项目中如何使用呢,首先我们要将架包导入进来在idea中点击file->Project Structure


然后点击OK即可这样对应的环境就配好了

粘贴上面我提到FaceEngineTest类但是有几个需要改的地方,最主要的就是appId 和sdkkey以及 需要换成自己目录下libs\WIN64这个地址
FaceEngine faceEngine = new FaceEngine("");

复制代码
import com.arcsoft.face.*;
import com.arcsoft.face.enums.*;
import com.arcsoft.face.toolkit.ImageInfo;

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

import com.arcsoft.face.toolkit.ImageInfoEx;

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 = "";//之前的官网让复制的两个地方
    String sdkKey = "";

    //这个地址需要换成自己目录下libs\WIN64这个地址
    FaceEngine faceEngine = new FaceEngine("");
    //激活引擎
    int errorCode = faceEngine.activeOnline(appId, sdkKey);

    if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
        System.out.println("引擎激活失败");
    }
     ActiveFileInfo activeFileInfo=new ActiveFileInfo();
    errorCode = faceEngine.getActiveFileInfo(activeFileInfo);
    if (errorCode != ErrorInfo.MOK.getValue() && errorCode != 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_ALL_OUT);
    engineConfiguration.setDetectFaceMaxNum(10);
    engineConfiguration.setDetectFaceScaleVal(16);
    //功能配置
    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);
     //初始化引擎
    errorCode = faceEngine.init(engineConfiguration);

    if (errorCode != ErrorInfo.MOK.getValue()) {
        System.out.println("初始化引擎失败");
    }
    //人脸检测
    ImageInfo imageInfo = getRGBData(new File(""));//图片一的地址
    List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();
    errorCode = faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
    System.out.println(faceInfoList);

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

    //人脸检测2
    ImageInfo imageInfo2 = getRGBData(new File(""));//图片二的地址
    List<FaceInfo> faceInfoList2 = new ArrayList<FaceInfo>();
    errorCode = faceEngine.detectFaces(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(),imageInfo2.getImageFormat(), faceInfoList2);
    System.out.println(faceInfoList2);

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

    //特征比对
    FaceFeature targetFaceFeature = new FaceFeature();
    targetFaceFeature.setFeatureData(faceFeature.getFeatureData());
    FaceFeature sourceFaceFeature = new FaceFeature();
    sourceFaceFeature.setFeatureData(faceFeature2.getFeatureData());
    FaceSimilar faceSimilar = new FaceSimilar();

    errorCode = faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);

    System.out.println("相似度:" + faceSimilar.getScore());

    //设置活体测试
    errorCode = faceEngine.setLivenessParam(0.5f, 0.7f);
    //人脸属性检测
    FunctionConfiguration configuration = new FunctionConfiguration();
    configuration.setSupportAge(true);
    configuration.setSupportFace3dAngle(true);
    configuration.setSupportGender(true);
    configuration.setSupportLiveness(true);
    errorCode = faceEngine.process(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList, configuration);
      //人脸检测
    ImageInfo imageInfo = getRGBData(new File(""));//图片一的地址
    List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();
    errorCode = faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
    System.out.println(faceInfoList);

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

    //人脸检测2
    ImageInfo imageInfo2 = getRGBData(new File(""));//图片二的地址
    List<FaceInfo> faceInfoList2 = new ArrayList<FaceInfo>();
    errorCode = faceEngine.detectFaces(imageInfo2.getImageData(), imageInfo2.getWidth(), imageInfo2.getHeight(),imageInfo2.getImageFormat(), faceInfoList2);
    System.out.println(faceInfoList2);

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

    //特征比对
    FaceFeature targetFaceFeature = new FaceFeature();
    targetFaceFeature.setFeatureData(faceFeature.getFeatureData());
    FaceFeature sourceFaceFeature = new FaceFeature();
    sourceFaceFeature.setFeatureData(faceFeature2.getFeatureData());
    FaceSimilar faceSimilar = new FaceSimilar();

    errorCode = faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);

    System.out.println("相似度:" + faceSimilar.getScore());

    //设置活体测试
    errorCode = faceEngine.setLivenessParam(0.5f, 0.7f);
    //人脸属性检测
    FunctionConfiguration configuration = new FunctionConfiguration();
    configuration.setSupportAge(true);
    configuration.setSupportFace3dAngle(true);
    configuration.setSupportGender(true);
    configuration.setSupportLiveness(true);
    errorCode = faceEngine.process(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList, configuration);
     //性别检测
    List<GenderInfo> genderInfoList = new ArrayList<GenderInfo>();
    errorCode = faceEngine.getGender(genderInfoList);
    System.out.println("性别:" + genderInfoList.get(0).getGender());

    //年龄检测
    List<AgeInfo> ageInfoList = new ArrayList<AgeInfo>();
    errorCode = faceEngine.getAge(ageInfoList);
    System.out.println("年龄:" + ageInfoList.get(0).getAge());

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

    //活体检测
    List<LivenessInfo> livenessInfoList = new ArrayList<LivenessInfo>();
    errorCode = faceEngine.getLiveness(livenessInfoList);
    System.out.println("活体:" + livenessInfoList.get(0).getLiveness());
        //IR属性处理
    ImageInfo imageInfoGray = getGrayData(new File("d:\\IR_480p.jpg"));//比对的图片地址
    List<FaceInfo> faceInfoListGray = new ArrayList<FaceInfo>();
    errorCode = faceEngine.detectFaces(imageInfoGray.getImageData(), imageInfoGray.getWidth(), imageInfoGray.getHeight(), imageInfoGray.getImageFormat(), faceInfoListGray);

    FunctionConfiguration configuration2 = new FunctionConfiguration();
    configuration2.setSupportIRLiveness(true);
    errorCode = faceEngine.processIr(imageInfoGray.getImageData(), imageInfoGray.getWidth(), imageInfoGray.getHeight(), imageInfoGray.getImageFormat(), faceInfoListGray, configuration2);
    //IR活体检测
    List<IrLivenessInfo> irLivenessInfo = new ArrayList<>();
    errorCode = faceEngine.getLivenessIr(irLivenessInfo);
    System.out.println("IR活体:" + irLivenessInfo.get(0).getLiveness());

    ImageInfoEx 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});
    List<FaceInfo> faceInfoList1 = new ArrayList<>();
    errorCode = faceEngine.detectFaces(imageInfoEx, DetectModel.ASF_DETECT_MODEL_RGB, faceInfoList1);

    FunctionConfiguration fun = new FunctionConfiguration();
    fun.setSupportAge(true);
    errorCode = faceEngine.process(imageInfoEx, faceInfoList1, functionConfiguration);
    List<AgeInfo> ageInfoList1 = new ArrayList<>();
    int age = faceEngine.getAge(ageInfoList1);
    System.out.println("年龄:" + ageInfoList1.get(0).getAge());

    FaceFeature feature = new FaceFeature();
    errorCode = faceEngine.extractFaceFeature(imageInfoEx, faceInfoList1.get(0), feature);
        //引擎卸载
    errorCode = faceEngine.unInit();

   }
}
    

给大家看看我的照片比对效果

活体:1代表是人

性别:0代表男,代表1

具体属性请看下载SDK的doc文件夹下第一个pdf里面有详细介绍

posted @   curry库-04049  阅读(89)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示