红软人脸识别sdk部署源码4.1版本

1.win系统收费版本源码pom 文件引入官方sdk

<dependency>
    <groupId>arcsoft</groupId>
    <artifactId>arcsoft</artifactId>
    <version>4.1.1</version>
    <scope>system</scope>
    <systemPath>
        ${project.basedir}/src/main/resources/lib/arcsoft-sdk-face-4.1.1.0.jar
    </systemPath>
</dependency>

2.启动配置文件项

@Configuration
public class FaceProConfig implements DisposableBean {


    @Value("${api.appId}")
    private String appId;

    @Value("${api.sdkKey}")
    private String sdkKey;

    @Value("${api.activeKey}")
    private String activeKey;

    @Value("${api.facePath}")
    private String facePath;

    @Value("${api.outLine}")
    private Boolean outLine;

    @Value("${api.outLinePath}")
    private String outLinePath;

    public FaceEngine faceEngine;

    @Bean
    public void getInit() {
        //从官网获取
        this.faceEngine = new FaceEngine(facePath);
        //激活引擎
        int errorCode = faceEngine.activeOnline(appId, sdkKey, activeKey);
        System.out.println("引擎激活errorCode:" + errorCode);

        ActiveDeviceInfo activeDeviceInfo = new ActiveDeviceInfo();
        //采集设备信息(可离线)
        errorCode = faceEngine.getActiveDeviceInfo(activeDeviceInfo);
        System.out.println("采集设备信息errorCode:" + errorCode);
        System.out.println("设备信息:" + activeDeviceInfo.getDeviceInfo());
        // 离线激活
        if(ObjectUtils.isNotNull(outLine) && outLine) {
            AssertUtil.assertNull(outLinePath,"离线激活时,离线激活文件路径缺失");
            faceEngine.activeOffline(outLinePath);
        }

        ActiveFileInfo activeFileInfo = new ActiveFileInfo();
        errorCode = faceEngine.getActiveFileInfo(activeFileInfo);
        System.out.println("获取激活文件errorCode:" + errorCode);
        System.out.println("激活文件信息:" + activeFileInfo.toString());

        //引擎配置
        EngineConfiguration engineConfiguration = new EngineConfiguration();
        engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);
        engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_ALL_OUT);
        engineConfiguration.setDetectFaceMaxNum(10);
        //功能配置
        //功能配置
        FunctionConfiguration functionConfiguration = new FunctionConfiguration();
        functionConfiguration.setSupportAge(true);
        functionConfiguration.setSupportFaceDetect(true);
        functionConfiguration.setSupportFaceRecognition(true);
        functionConfiguration.setSupportGender(true);
        functionConfiguration.setSupportLiveness(true);
        functionConfiguration.setSupportIRLiveness(true);
        functionConfiguration.setSupportImageQuality(true);
        functionConfiguration.setSupportMaskDetect(true);
        functionConfiguration.setSupportUpdateFaceData(true);
        engineConfiguration.setFunctionConfiguration(functionConfiguration);

        //初始化引擎
        errorCode = faceEngine.init(engineConfiguration);
        System.out.println("初始化引擎errorCode:" + errorCode);
        VersionInfo version = faceEngine.getVersion();
        System.out.println(version);

        if (errorCode != ErrorInfo.MOK.getValue()) {
            System.out.println("初始化引擎失败");
        }
        this.faceEngine = faceEngine;
    }

    @Override
    public void destroy() throws Exception {
        //引擎卸载
        System.out.println("引擎卸载");
        int errorCode = faceEngine.unInit();
        System.out.println("errorCode" + errorCode);
    }
}

3.注册人脸,识别人脸工具类封装

@Slf4j
@Component
public class FacesproUtils {
    private int errorCode;
    private String num = "0.8005857";

    @Autowired
    private FaceProConfig faceConfig;

    //特征提取
    public byte[] getFace(String path){
        //人脸检测
        try{
            File file= new File(path);
            if(!file.exists())
            {
                log.info("人脸图片找不到");
                return null;
            }
            log.info("sdk获取人脸资源");
            ImageInfo imageInfo = getRGBData(file);
            log.info("sdk获取人脸imageInfo"+imageInfo);
            if(null == imageInfo){
                log.info("imageInfo"+imageInfo);
                return null;
            }
            List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();
            log.info("--faceInfoList--"+faceInfoList);
            errorCode = faceConfig.faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
            FaceFeature faceFeature = new FaceFeature();
            log.info("--faceFeature--"+faceFeature);
            errorCode = faceConfig.faceEngine.extractFaceFeature(imageInfo, faceInfoList.get(0), ExtractType.RECOGNIZE, 0, faceFeature);
            log.info("--人脸提取"+faceFeature.getFeatureData());
            return faceFeature.getFeatureData();
        }catch (Exception e){
            log.info("--人脸提取异常--null");
            return null;
        }
    }

    //注册特征提取
    public byte[] getFaceZ(String path){
        try{
            File file= new File(path);
            if(!file.exists())
            {
                return null;
            }
            //人脸检测
            ImageInfo imageInfo = getRGBData(file);
            if(null == imageInfo){
                return null;
            }
            List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();
            errorCode = faceConfig.faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
            FaceFeature faceFeature = new FaceFeature();
            errorCode = faceConfig.faceEngine.extractFaceFeature(imageInfo, faceInfoList.get(0), ExtractType.REGISTER, 0, faceFeature);
            return faceFeature.getFeatureData();
        }catch (Exception e){
            return null;
        }
    }

    //特征比对
    public boolean faceSimilar(FaceFeature oneFace,FaceFeature TwoFace){
        try{
            log.info("特征比对");
            //特征比对
            FaceSimilar faceSimilar = new FaceSimilar();
            errorCode = faceConfig.faceEngine.compareFaceFeature(oneFace,TwoFace, faceSimilar);
            log.info("相似度"+faceSimilar.getScore());
//            System.out.println("相似度:" + faceSimilar.getScore());
            BigDecimal b1 = new BigDecimal(Float.toString(faceSimilar.getScore()));
            BigDecimal num = new BigDecimal(this.num);
            if(b1.compareTo(num)  > -1){
                return true;
            }else{
                return false;
            }
        }catch (Exception e){
       log.info("特征比对异常");
            return false;
        }

    }

    public FaceFeature faceFeature(byte[] Face){
        try{
            log.info("--faceFeature--"+Face);
            if(null == Face){
                log.info("--Face-null-");
                return null;
            }
            FaceFeature targetFaceFeature = new FaceFeature();
            log.info("--targetFaceFeature--");
            targetFaceFeature.setFeatureData(Face);
            return targetFaceFeature;
        }catch (Exception e){
            log.info("人脸特征提取异常");
            return null;
        }

    }

    public String jihuo(){
        ActiveDeviceInfo activeDeviceInfo = new ActiveDeviceInfo();
        //采集设备信息(可离线)
        errorCode = faceConfig.faceEngine.getActiveDeviceInfo(activeDeviceInfo);
        System.out.println("采集设备信息errorCode:" + errorCode);
        System.out.println("设备信息:" + activeDeviceInfo.getDeviceInfo());
        return activeDeviceInfo.getDeviceInfo();
    }

}

 注意配置项启动redis作为人脸缓存,比对数据库人脸特征值,百万级人脸比对

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值