兰坪人脸识别key更新,jar包提交
This commit is contained in:
parent
c2f20432c6
commit
e1c1a4b8d0
Binary file not shown.
|
|
@ -1,7 +1,7 @@
|
|||
package com.bonus.bmw.person.utils;
|
||||
|
||||
import com.arcsoft.face.*;
|
||||
import com.arcsoft.face.enums.ImageFormat;
|
||||
import com.arcsoft.face.enums.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.color.ColorSpace;
|
||||
|
|
@ -30,13 +30,13 @@ public class ArcFaceHelper {
|
|||
* linux_64
|
||||
*/
|
||||
private static final String LINUX64_SDK_KEY = "GggpcEphVxXLXcpEZz6tdC19evqXbbhMyYt71DGLwnCp";
|
||||
|
||||
private static FaceEngine faceEngine = null;
|
||||
|
||||
public static final float STANDARD_SCORE = 0.85F;
|
||||
|
||||
static {
|
||||
try{
|
||||
private static FaceEngine faceEngine = null;
|
||||
|
||||
public static final float STANDARD_SCORE = 0.85F;
|
||||
|
||||
static {
|
||||
try{
|
||||
String os = System.getProperty("os.name");
|
||||
if(StringUtils.startsWith(os.toLowerCase(), "win")){
|
||||
faceEngine = new FaceEngine("D:\\arcsoft_lib_64");
|
||||
|
|
@ -50,28 +50,28 @@ public class ArcFaceHelper {
|
|||
}catch (Throwable e){
|
||||
System.out.println("加载人脸识别引擎异常:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static FaceEngine getFaceEngine() {
|
||||
return faceEngine;
|
||||
}
|
||||
|
||||
public FaceResult getFaceFeatures(String imgSrc) {
|
||||
}
|
||||
|
||||
public static FaceEngine getFaceEngine() {
|
||||
return faceEngine;
|
||||
}
|
||||
|
||||
public FaceResult getFaceFeatures(String imgSrc) {
|
||||
if(imgSrc.contains("http")){
|
||||
return getFaceFeatures(getNetUrlHttp(imgSrc));
|
||||
}else{
|
||||
return getFaceFeatures(new File(imgSrc));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static FaceResult getFaceFeatures(File file) {
|
||||
ImageInfo imageInfo = getRGBData(file);
|
||||
if (imageInfo == null){
|
||||
public static FaceResult getFaceFeatures(File file) {
|
||||
ImageInfo imageInfo = getRGBData(file);
|
||||
if (imageInfo == null){
|
||||
return null;
|
||||
}
|
||||
EngineConfiguration engineConfiguration = EngineConfiguration.builder().functionConfiguration(
|
||||
EngineConfiguration engineConfiguration = EngineConfiguration.builder().functionConfiguration(
|
||||
FunctionConfiguration.builder()
|
||||
.supportFaceDetect(true)
|
||||
.supportFaceDetect(true)
|
||||
.supportAge(true)
|
||||
.supportFace3dAngle(true)
|
||||
.supportFaceDetect(true)
|
||||
|
|
@ -82,24 +82,24 @@ public class ArcFaceHelper {
|
|||
faceEngine.init(engineConfiguration);
|
||||
//人脸检测
|
||||
List<FaceInfo> lstFaceInfo = new ArrayList<FaceInfo>();
|
||||
faceEngine.detectFaces(imageInfo.getRgbData(), imageInfo.getWidth(), imageInfo.getHeight(),
|
||||
ImageFormat.CP_PAF_BGR24, lstFaceInfo);
|
||||
faceEngine.detectFaces(imageInfo.getRgbData(), imageInfo.getWidth(), imageInfo.getHeight(),
|
||||
ImageFormat.CP_PAF_BGR24, lstFaceInfo);
|
||||
System.out.println("检测到人脸数:" + lstFaceInfo.size());
|
||||
if (lstFaceInfo.size() == 0) {
|
||||
return null;
|
||||
// throw new NullPointerException("未检测到人脸");
|
||||
}
|
||||
}
|
||||
FaceResult result = new FaceResult();
|
||||
//提取人脸特征
|
||||
FaceFeature faceFeature = new FaceFeature();
|
||||
int code = faceEngine.extractFaceFeature(imageInfo.getRgbData(), imageInfo.getWidth(), imageInfo.getHeight(),
|
||||
ImageFormat.CP_PAF_BGR24, lstFaceInfo.get(0), faceFeature);
|
||||
int code = faceEngine.extractFaceFeature(imageInfo.getRgbData(), imageInfo.getWidth(), imageInfo.getHeight(),
|
||||
ImageFormat.CP_PAF_BGR24, lstFaceInfo.get(0), faceFeature);
|
||||
System.out.println("提取特征结果码:" + code);
|
||||
result.setFeatures(faceFeature.getFeatureData());
|
||||
//人脸信息检测
|
||||
int processCode = faceEngine.process(imageInfo.getRgbData(), imageInfo.getWidth(), imageInfo.getHeight(),
|
||||
ImageFormat.CP_PAF_BGR24, lstFaceInfo,
|
||||
FunctionConfiguration.builder().supportAge(true).supportFace3dAngle(true).supportGender(true).build());
|
||||
int processCode = faceEngine.process(imageInfo.getRgbData(), imageInfo.getWidth(), imageInfo.getHeight(),
|
||||
ImageFormat.CP_PAF_BGR24, lstFaceInfo,
|
||||
FunctionConfiguration.builder().supportAge(true).supportFace3dAngle(true).supportGender(true).build());
|
||||
System.out.println("人脸信息检测码:" + processCode);
|
||||
if(code != 0 || processCode != 0){
|
||||
return null;
|
||||
|
|
@ -122,14 +122,14 @@ public class ArcFaceHelper {
|
|||
System.out.println("3D信息:" + face3DAngleList + ",3D信息提取码:" + face3dCode);
|
||||
unInintEngine();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static void unInintEngine() {
|
||||
int code = faceEngine.unInit();
|
||||
System.out.println("销毁引擎:" + code);
|
||||
}
|
||||
|
||||
public static ImageInfo getRGBData(File file) {
|
||||
public static void unInintEngine() {
|
||||
int code = faceEngine.unInit();
|
||||
System.out.println("销毁引擎:" + code);
|
||||
}
|
||||
|
||||
public static ImageInfo getRGBData(File file) {
|
||||
if (file == null){
|
||||
return null;
|
||||
}
|
||||
|
|
@ -163,18 +163,18 @@ public class ArcFaceHelper {
|
|||
//进行数据格式化为可用数据
|
||||
BufferedImage dstImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
|
||||
try {
|
||||
if (resultImage.getType() != BufferedImage.TYPE_3BYTE_BGR) {
|
||||
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
|
||||
ColorConvertOp colorConvertOp = new ColorConvertOp(cs, dstImage.createGraphics().getRenderingHints());
|
||||
colorConvertOp.filter(resultImage, dstImage);
|
||||
} else {
|
||||
dstImage = resultImage;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
System.err.println(e.toString());
|
||||
}
|
||||
|
||||
if (resultImage.getType() != BufferedImage.TYPE_3BYTE_BGR) {
|
||||
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
|
||||
ColorConvertOp colorConvertOp = new ColorConvertOp(cs, dstImage.createGraphics().getRenderingHints());
|
||||
colorConvertOp.filter(resultImage, dstImage);
|
||||
} else {
|
||||
dstImage = resultImage;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
System.err.println(e.toString());
|
||||
}
|
||||
|
||||
//获取rgb数据
|
||||
imageInfo.setRgbData(((DataBufferByte) (dstImage.getRaster().getDataBuffer())).getData());
|
||||
return imageInfo;
|
||||
|
|
@ -241,5 +241,5 @@ public class ArcFaceHelper {
|
|||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue