人脸识别深入认识

人脸识别系统再认识

本次试验,希望能够学习到类似人脸打卡系统,通过一张静态图片可以从数据库中调出该人物的身份。

理论支持

在第一次的学习中,我发现了SDK提到了一个对象“feature”,里边可能存在人脸部信息的数据

根据上次的学习———-搭建一个项目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package dwx;

import com.arcsoft.face.ActiveFileInfo;
import com.arcsoft.face.EngineConfiguration;
import com.arcsoft.face.FaceEngine;
import com.arcsoft.face.FunctionConfiguration;
import com.arcsoft.face.enums.DetectMode;
import com.arcsoft.face.enums.DetectOrient;
import com.arcsoft.face.enums.ErrorInfo;
import com.arcsoft.face.toolkit.ImageInfo;

import java.io.File;

import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;

public class MyAreFaceTest {

public static void main(String[] args) {

//启动引擎
String appId = "7K7KG9zfBVXbxoG3cxqKmpF1DwijXxJ73s75v7uZqxoT";
String sdkKey = "AuyJJAcGDtzSnK8wz2Dekrk28QmK1BnD5wXzSEPtXs5C";

//启动引擎的地址
String dllAddress = "D:\\AreFace\\libs\\WIN64";
FaceEngine faceEngine = new FaceEngine(dllAddress);

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();

//检测模式设置
//这里因为我们是对图片进行人脸识别,因此这里我们使用一个IMAGE模式
engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);

//可检测图片人脸方向设置
engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_ALL_OUT);//这里我设置的是全方位角设置
engineConfiguration.setDetectFaceMaxNum(40);//最大识别人脸数量
engineConfiguration.setDetectFaceScaleVal(16);//识别等级

//设置引擎功能
//功能配置,可以设置面容识别时是否分析年龄、性别、3d等。
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("引擎初始化失败");
}


//关闭引擎
faceEngine.unInit();
System.out.println("=================程序结束===================");

}
}

提取图片中的信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//图片所在的文件路径
String fileUrl = "D:\\AreFace\\AreFaceTest\\";
//文件名称
String fileName = "aaa.jpg";
File file1 = new File(fileUrl + fileName);
ImageInfo imageInfo = getRGBData(file1);
//获得一个图片里的所有人脸信息
List<FaceInfo> faceInfos = new ArrayList<>();

faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(),imageInfo.getHeight() ,imageInfo.getImageFormat(),faceInfos);

//展示所有的人脸信息
for (FaceInfo faceInfo : faceInfos) {
System.out.println(faceInfo);
}



//获得feature
FaceFeature faceFeature = new FaceFeature();
faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(),imageInfo.getHeight() ,imageInfo.getImageFormat(),faceInfos.get(0),faceFeature);

//输出特征值
System.out.println("feature数据位:"+ Arrays.toString(faceFeature.getFeatureData()));


获得的数据不知道是什么意思

1
2
feature数据位:[0, -128, -6, 68, 0, 0, -96, 65, -68, -21, 67, 61, -114, -43, 119, -68, -121, 0, -42, 61, 4, 7, -46, -68, 42, -1, -110, 61, -69, -114, -91, -67, 49, -60, 8, 60, 71, 71, -41, -67, -102, -119, 71, 57, 108, -77, -59, 61, 115, -20, 4, -67, 112, -28, 30, 58, -64, 48, 110, -67, 119, 84, -31, 61, 34, 96, -92, -67, 119, -3, -65, 61, 5, 123, -124, 61, 101, -97, 117, -67, -79, 53, 35, 61, -76, -124, -114, 61, -32, 85, 114, 60, 95, -89, -52, -67, 36, 93, 90, -67, -121, -20, -109, -68, -55, -91, 16, 61, -75, -64, 120, 59, 95, -80, -54, -67, -109, -92, 32, -67, 53, -99, 0, -67, -92, 74, -118, 61, 12, 97, -65, 60, -5, -60, 61, 60, 55, 111, -58, -67, 81, 36, 53, -68, 35, 114, 15, -68, 66, 100, -25, -68, -75, -118, -109, -67, 98, -12, -74, 58, 67, 13, 28, -67, -61, -65, 4, -67, 82, -8, 67, 60, -14, -58, -102, -67, -110, -32, -84, 61, 9, -110, 36, 62, 91, -81, 30, 61, 52, -77, 3, -67, -121, 29, 78, 61, -83, 70, -92, 61, 77, -71, 26, -66, -89, -59, -18, -68, 32, -115, -113, 61, 113, 61, 48, 61, 29, 121, -104, 61, -128, 21, -42, -68, -109, 97, -61, -68, -123, 121, -128, 60, 54, -72, 41, -67, 3, 37, -55, 61, -67, -59, 8, 61, 89, 126, -125, 60, -43, 30, 9, 59, -81, 51, -110, -67, -4, -94, -84, -68, -47, 109, -38, -70, -50, -64, -70, 60, -50, 60, 30, -68, 36, 84, -62, -67, 6, 3, 14, 61, 20, -47, -119, -67, -7, 5, 126, 60, 45, 96, 45, -67, -127, -124, -72, -69, -59, -112, -77, 61, -83, 79, 36, -66, -87, -77, -30, 61, -16, -107, -90, -67, 27, -36, 116, -68, -65, 114, -105, -67, -93, 60, 6, -67, -20, -64, -125, -67, -81, 24, -72, -67, 19, -124, 35, -67, -22, 16, -126, 61, -46, 115, 107, 61, 77, 20, -40, -67, -27, 35, 90, -67, 78, -2, -65, 59, 68, -31, -128, 61, 58, -60, -99, -68, -127, -48, -76, -67, 83, -8, -108, -69, 12, -115, -89, -69, 95, 107, 116, -67, -95, -84, 109, -69, 69, 34, 22, 61, 79, -121, -71, -67, -36, -121, 61, 61, 113, -98, 48, -67, -13, 65, -47, -67, -48, 123, -1, -67, -127, -6, 60, -67, 44, 126, -50, -71, 18, -78, 10, -67, 98, -51, -116, -69, 90, -92, 50, 61, -30, 115, 41, -67, -99, -26, -104, 61, 48, -82, -18, 61, 48, -104, 39, -66, -63, 35, 13, -69, 67, 60, -105, -67, -85, -38, 15, 61, -73, 4, -101, 60, -124, 16, -43, 61, -37, 114, 77, 60, -106, 9, -120, 61, -113, -26, 78, -69, -127, 26, 32, 62, -62, -77, -80, 61, -115, -86, 105, 61, -61, 22, 38, 61, 62, -19, -48, -68, -55, 36, 58, -67, 21, -77, -70, 60, 73, -41, -101, 59, -34, 14, -110, -67, -94, 124, 46, 61, 111, -12, 11, 61, 82, 99, -10, 58, -103, -84, -99, 61, 76, -70, -94, 61, -18, -79, 100, 59, -46, -22, 59, 61, -23, 26, -42, -67, 112, 102, 78, 60, -50, -79, 76, -67, -117, 70, -27, -70, 100, 35, -37, -67, -81, -98, 42, -67, 100, 18, 127, -67, 89, -28, -48, 61, -60, 72, -50, 61, 16, 22, 62, 61, 116, 104, 75, 61, 23, 75, 18, 61, 18, -17, -118, -68, 92, 47, 70, -67, 93, -97, 40, -67, 31, 50, 94, -68, -96, -6, -106, -67, -39, 90, 85, 59, 61, 116, 94, 61, -114, 75, 35, 61, 116, 30, 123, -67, -99, 60, -64, -68, 16, 120, -80, -67, 105, -9, 25, -66, 62, 49, 3, -66, -52, 11, 17, 59, 63, 87, 76, -68, 34, -102, 51, -68, 20, -91, -97, -67, 103, 18, -85, 60, 94, -8, 104, 58, 28, 75, -76, 61, -41, -121, -29, -67, 46, 27, -3, 60, 122, -95, -63, -67, 5, 39, 89, 61, -18, 72, -18, 58, 124, -51, -125, 58, -3, -47, 27, -68, 49, 94, 99, 61, 100, 54, -34, 61, 114, -106, 62, 61, 15, -34, 57, 59, -101, -8, 76, 60, 20, -70, -55, 59, 124, 42, 58, -67, 47, 38, 2, 61, -37, -24, -67, 61, 69, -35, -128, 61, 54, 17, 115, -68, -100, 110, -93, 60, -57, 116, -12, -67, 34, 48, 70, 61, -78, -16, 21, -68, 50, -19, -15, 60, -28, 3, 117, -67, -76, -124, -73, 60, -2, 46, -82, -69, 55, -105, 126, -67, -65, -120, -82, 61, -42, 108, 107, -68, -101, -48, -111, -67, -95, -22, 114, -67, -31, 127, 97, 61, 93, -122, -87, -67, 76, -5, -76, -68, 99, 12, 113, -68, -2, -5, 79, -68, 79, -17, 8, -67, 3, 89, -44, -68, 50, -120, -112, 61, -115, 20, 11, 60, 124, -118, 47, 61, 110, 111, 105, -67, 122, -15, 4, 62, 67, 64, -97, 60, -44, 85, -79, 60, 105, 40, 100, 61, 122, -95, 118, -67, 12, -99, -83, -67, -96, 94, -115, 60, -75, -39, -109, 61, -7, 79, -29, 61, -125, -79, -126, 61, -126, -77, 102, -67, -1, -7, -76, -67, -66, -30, 44, -67, 4, -91, -45, 61, -66, -36, 59, -67, -31, 120, 47, -67, 80, 63, -116, -67, 108, -74, -38, -67, -127, 51, -13, 61, 109, 111, -111, 61, -87, 106, -116, -67, -111, -91, 91, -67, -23, 120, -118, -67, -48, -34, 114, 60, -99, -124, 25, 59, 94, 44, -77, -68, 17, 12, -77, -68, 27, 108, 65, 61, 85, 12, 40, 60, -79, -63, 4, 61, 65, -79, -55, -67, -79, -23, -46, 61, 1, -122, -106, -68, -84, 40, -44, -67, 83, -24, 99, -67, 20, 37, -81, 61, -59, 84, -67, -70, -86, 74, -1, 60, -50, -118, 11, -68, -31, -16, -39, -68, -92, -64, -92, -68, -125, 12, -128, -67, -125, -72, -17, 60, -118, 41, 49, -67, 18, 78, 121, 61, 95, -31, -48, 60, 63, 113, -108, -68, 126, -13, 99, 61, 35, 21, 72, 58]

继续分析其他的图片的feature来获得这个数据的意义

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//获得第二张图片的人脸数据
String fileName2 = "bbb.jpg";
File file2 = new File(fileUrl + fileName2);

ImageInfo imageInfo1 = getRGBData(file2);

ArrayList<FaceInfo> faceInfos1 = new ArrayList<>();

faceEngine.detectFaces(imageInfo1.getImageData(), imageInfo.getWidth(),imageInfo1.getHeight(),imageInfo1.getImageFormat(),faceInfos1);

for (FaceInfo faceInfo : faceInfos1) {
System.out.println(faceInfo);
}

FaceFeature faceFeature1 = new FaceFeature();
faceEngine.extractFaceFeature(imageInfo1.getImageData(), imageInfo.getWidth(),imageInfo1.getHeight(),imageInfo1.getImageFormat(),faceInfos1.get(0),faceFeature1);

//输出第二正图片的feature
System.out.println(Arrays.toString(faceFeature1.getFeatureData()));

1
[0, -128, -6, 68, 0, 0, -96, 65, 11, -80, -119, 61, -75, -91, 56, -69, 6, 119, 23, 62, -14, 33, -43, -67, -35, -127, 45, -68, -104, -2, 82, -67, -68, -121, 91, -68, 102, 92, -93, -67, 52, 9, -123, -67, -125, -37, 95, 61, -6, 103, 40, -67, 33, 115, 50, -68, -37, 28, -34, -67, -61, 100, -76, 61, -40, -54, -85, -67, -104, 107, -50, 61, 46, -52, -116, 61, -21, -53, -78, -67, 26, 19, -34, 61, -104, -53, -96, 61, -82, -64, -95, 60, -4, -55, -67, -67, 120, -89, 106, -67, -37, 72, -17, -68, -16, -19, -55, 60, 30, 123, -19, 61, 119, -28, -63, -67, 53, -90, -72, -67, -2, -32, -6, 60, 96, -69, -67, 61, -61, -64, 48, 61, -9, -123, -117, -68, 75, -106, 41, -67, 70, 107, -21, 60, 60, 116, 37, -67, -3, -124, 6, -70, -8, 66, -20, -69, -39, 75, 108, -68, -27, 103, -72, -67, -17, 73, 73, -67, 37, 114, 64, 61, 26, 25, -80, -67, -90, -71, 97, 61, -28, -77, -20, 61, 66, -111, -59, -70, -98, -6, -88, -68, 119, -42, -37, 60, 37, -92, -90, 60, -50, -94, 39, -66, 0, -69, -107, -68, -13, 64, -42, 61, 60, -103, -121, 61, 106, 118, -1, 61, 60, -82, -127, -67, -69, 21, -84, -68, 14, -2, 18, 61, 22, -36, 0, -68, 71, -33, -62, 61, 123, 21, -55, 60, -126, -60, 41, 61, -124, -79, -60, -71, 65, 85, -93, -67, 48, 105, -101, 59, -116, 118, -42, -68, -39, -54, -84, 59, -28, 33, 73, 61, 79, -71, -9, -67, 6, -66, 65, 61, -79, -66, -8, -67, -99, -42, -123, 61, 27, 61, 50, -67, -118, -89, 41, 61, -90, 76, -2, 61, 78, 107, 35, -66, 57, 80, -107, 61, -124, 77, 30, -67, 82, -25, 123, -67, 1, -85, -105, -67, 66, -29, 54, 60, -39, 77, -65, -69, 64, -89, -29, -68, 78, 77, 56, -67, -8, -82, -98, 60, 83, 51, 115, 61, 37, -62, 27, -67, 70, -89, -122, -67, 0, 14, -43, -68, -7, -71, 15, 62, 5, -26, 53, 60, 74, -19, -58, -67, 52, -22, 2, 61, 89, -18, -36, -69, -77, 86, 82, -67, -36, -81, 52, 60, 49, -115, 124, 61, -30, 116, -62, -67, 29, 116, 25, 61, -20, -47, 43, -67, -10, -120, 3, -66, -38, -28, 0, -66, 67, 78, 42, -67, -75, 83, -32, -68, -102, 87, -97, -67, -112, -81, 80, 59, -76, -39, 94, 61, 66, 106, 16, -67, 1, -104, 37, 60, -105, 84, -36, 61, -78, -76, -37, -67, 60, 0, 84, 58, -82, -76, -112, -67, -105, -18, 25, 61, -18, 94, -120, -68, 84, 35, -69, 61, 15, 36, -128, -69, 103, 122, 54, 60, -98, 30, -123, 61, 34, 125, 13, 62, -2, -60, -123, 61, 6, 49, -121, 61, -93, 25, -71, 60, 31, -124, 109, -67, -24, 97, 75, -67, 26, 40, -117, 61, 102, 36, -107, 61, -39, 87, 100, -67, 64, -64, 18, 61, -87, 110, -126, 60, -62, -24, 15, -67, -122, 106, -127, 61, 35, -4, -51, 61, -40, -81, 55, -67, -111, -5, 43, -68, 65, -51, 2, -66, -13, 60, 45, 61, -108, -109, -6, -68, -73, 53, 21, -67, -68, 36, -58, -67, -112, -83, 1, 61, -98, 45, -5, -67, -61, -59, -63, 61, 82, -107, 27, 61, -20, 2, -109, 61, -37, 56, 26, -67, 106, -119, -33, -68, -7, 75, -14, 58, 64, -76, 3, -67, 41, -35, 38, -67, -51, -24, 60, -68, 44, 67, 11, -67, 87, 103, 108, 60, -12, -5, 84, 61, -2, 70, 48, 61, -54, 41, -67, -68, 16, 107, -85, -68, -21, -29, -14, -67, 61, -107, 6, -66, -56, -74, -40, -67, -77, 30, -17, -68, -61, -56, -85, 60, -79, 81, -120, -67, -5, -45, 108, -67, 102, -54, -71, 60, 82, 62, 4, 61, -107, -12, 80, 61, 93, 20, -99, -68, -92, 104, 97, 59, -24, -76, 5, -67, -29, -13, 44, 61, -95, -93, -44, -68, 82, -108, 25, -67, -101, 93, 53, 60, -119, -59, 11, 61, 11, 67, -38, 60, 93, -107, -123, 60, 9, -18, 29, -67, -24, -33, -84, 61, 5, -47, -116, -67, 38, -97, -62, -67, 101, -26, 30, 60, -79, 85, -66, 61, -64, 76, -8, 60, -110, -112, -126, 58, 32, -5, -1, 59, -67, -105, 15, -66, -126, -23, -77, 61, -95, -37, 33, 60, -44, -80, -9, -69, -59, -15, -101, -67, 52, -27, -82, 60, 94, 100, 6, -68, -58, -79, 114, -68, -109, 16, 48, 61, -94, -106, 0, -67, 86, -42, -22, -68, -96, 107, -92, -67, -86, 121, 64, 61, -120, -75, -63, -67, -105, -92, 85, -67, 93, 120, 34, -67, -54, 12, -28, -68, 23, 43, 16, -67, -120, 89, 47, -68, 56, 126, 15, 62, -18, 42, -99, 60, -11, 52, 28, 61, -84, 123, 118, -67, 117, 36, 16, 62, -59, 28, -61, 61, -95, 122, 102, 61, 60, 38, -99, 61, -38, -80, 32, -68, 118, 69, -65, -67, -7, -33, 9, 61, 9, 36, -13, 61, -61, -87, -66, 61, 112, 114, -124, 61, 29, 112, -111, -67, -39, 91, 0, -66, 121, -38, -55, -67, -63, 11, 4, 61, -51, 89, -115, -67, 28, -74, 58, 60, 14, 122, -105, -67, 84, 108, 5, -66, -91, 35, -41, 61, 100, 13, -38, 61, -33, 125, 85, -68, 93, 25, -111, -67, 107, -30, 37, -67, 63, -117, 57, 60, -1, 68, 48, 61, -115, 5, -120, 61, -26, 50, -103, 60, -60, 39, -122, 61, 84, 117, -71, -69, 29, 98, 110, 61, 54, 108, -67, -67, -115, -125, -111, 61, -117, 91, -99, 60, 68, -79, -112, -67, 16, -67, -122, -68, 62, -26, -8, 60, -57, 79, 105, -68, 7, 8, 48, -67, 41, 9, 123, 61, -29, -61, -97, -69, -95, 84, 114, -67, -45, 11, -6, -68, -90, -107, -90, -68, 119, -122, 82, -67, -58, -71, -122, 60, -42, -102, 120, 60, 56, 58, 105, -67, 32, -99, -49, 61, -67, 108, 56, 60]

不明白feature,但是这个东西可以存储

程序源码

xWv9Xj.png

源码说存储的是byte形式

构造器张这个样子 只有一个byte[]数组

xWv9Xj.png

xWvUjH.png

也可以这样创建

xWvdud.png

因此我们可以知道

我们可以获得一个对比图片的feature的人脸数据,一个byte[],我们可以将它转为String类型存储在数据库中,

然后如果需要人脸对比,从数据库中得到这个String,转换成byte[]再整合成一个feature对象

尝试一下这种方法

存储数据 即将超长数据存入String 从超长String获得byte[]中的方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
String data;
data = "0, -128, -6, 68, 0, 0, -96, 65, 11, -80, -119, 61, -75, -91, 56, -69, 6, 119, 23, 62, -14, 33, -43, -67, -35, -127, 45, -68, -104, -2, 82, -67, -68, -121, 91, -68, 102, 92, -93, -67, 52, 9, -123, -67, -125, -37, 95, 61, -6, 103, 40, -67, 33, 115, 50, -68, -37, 28, -34, -67, -61, 100, -76, 61, -40, -54, -85, -67, -104, 107, -50, 61, 46, -52, -116, 61, -21, -53, -78, -67, 26, 19, -34, 61, -104, -53, -96, 61, -82, -64, -95, 60, -4, -55, -67, -67, 120, -89, 106, -67, -37, 72, -17, -68, -16, -19, -55, 60, 30, 123, -19, 61, 119, -28, -63, -67, 53, -90, -72, -67, -2, -32, -6, 60, 96, -69, -67, 61, -61, -64, 48, 61, -9, -123, -117, -68, 75, -106, 41, -67, 70, 107, -21, 60, 60, 116, 37, -67, -3, -124, 6, -70, -8, 66, -20, -69, -39, 75, 108, -68, -27, 103, -72, -67, -17, 73, 73, -67, 37, 114, 64, 61, 26, 25, -80, -67, -90, -71, 97, 61, -28, -77, -20, 61, 66, -111, -59, -70, -98, -6, -88, -68, 119, -42, -37, 60, 37, -92, -90, 60, -50, -94, 39, -66, 0, -69, -107, -68, -13, 64, -42, 61, 60, -103, -121, 61, 106, 118, -1, 61, 60, -82, -127, -67, -69, 21, -84, -68, 14, -2, 18, 61, 22, -36, 0, -68, 71, -33, -62, 61, 123, 21, -55, 60, -126, -60, 41, 61, -124, -79, -60, -71, 65, 85, -93, -67, 48, 105, -101, 59, -116, 118, -42, -68, -39, -54, -84, 59, -28, 33, 73, 61, 79, -71, -9, -67, 6, -66, 65, 61, -79, -66, -8, -67, -99, -42, -123, 61, 27, 61, 50, -67, -118, -89, 41, 61, -90, 76, -2, 61, 78, 107, 35, -66, 57, 80, -107, 61, -124, 77, 30, -67, 82, -25, 123, -67, 1, -85, -105, -67, 66, -29, 54, 60, -39, 77, -65, -69, 64, -89, -29, -68, 78, 77, 56, -67, -8, -82, -98, 60, 83, 51, 115, 61, 37, -62, 27, -67, 70, -89, -122, -67, 0, 14, -43, -68, -7, -71, 15, 62, 5, -26, 53, 60, 74, -19, -58, -67, 52, -22, 2, 61, 89, -18, -36, -69, -77, 86, 82, -67, -36, -81, 52, 60, 49, -115, 124, 61, -30, 116, -62, -67, 29, 116, 25, 61, -20, -47, 43, -67, -10, -120, 3, -66, -38, -28, 0, -66, 67, 78, 42, -67, -75, 83, -32, -68, -102, 87, -97, -67, -112, -81, 80, 59, -76, -39, 94, 61, 66, 106, 16, -67, 1, -104, 37, 60, -105, 84, -36, 61, -78, -76, -37, -67, 60, 0, 84, 58, -82, -76, -112, -67, -105, -18, 25, 61, -18, 94, -120, -68, 84, 35, -69, 61, 15, 36, -128, -69, 103, 122, 54, 60, -98, 30, -123, 61, 34, 125, 13, 62, -2, -60, -123, 61, 6, 49, -121, 61, -93, 25, -71, 60, 31, -124, 109, -67, -24, 97, 75, -67, 26, 40, -117, 61, 102, 36, -107, 61, -39, 87, 100, -67, 64, -64, 18, 61, -87, 110, -126, 60, -62, -24, 15, -67, -122, 106, -127, 61, 35, -4, -51, 61, -40, -81, 55, -67, -111, -5, 43, -68, 65, -51, 2, -66, -13, 60, 45, 61, -108, -109, -6, -68, -73, 53, 21, -67, -68, 36, -58, -67, -112, -83, 1, 61, -98, 45, -5, -67, -61, -59, -63, 61, 82, -107, 27, 61, -20, 2, -109, 61, -37, 56, 26, -67, 106, -119, -33, -68, -7, 75, -14, 58, 64, -76, 3, -67, 41, -35, 38, -67, -51, -24, 60, -68, 44, 67, 11, -67, 87, 103, 108, 60, -12, -5, 84, 61, -2, 70, 48, 61, -54, 41, -67, -68, 16, 107, -85, -68, -21, -29, -14, -67, 61, -107, 6, -66, -56, -74, -40, -67, -77, 30, -17, -68, -61, -56, -85, 60, -79, 81, -120, -67, -5, -45, 108, -67, 102, -54, -71, 60, 82, 62, 4, 61, -107, -12, 80, 61, 93, 20, -99, -68, -92, 104, 97, 59, -24, -76, 5, -67, -29, -13, 44, 61, -95, -93, -44, -68, 82, -108, 25, -67, -101, 93, 53, 60, -119, -59, 11, 61, 11, 67, -38, 60, 93, -107, -123, 60, 9, -18, 29, -67, -24, -33, -84, 61, 5, -47, -116, -67, 38, -97, -62, -67, 101, -26, 30, 60, -79, 85, -66, 61, -64, 76, -8, 60, -110, -112, -126, 58, 32, -5, -1, 59, -67, -105, 15, -66, -126, -23, -77, 61, -95, -37, 33, 60, -44, -80, -9, -69, -59, -15, -101, -67, 52, -27, -82, 60, 94, 100, 6, -68, -58, -79, 114, -68, -109, 16, 48, 61, -94, -106, 0, -67, 86, -42, -22, -68, -96, 107, -92, -67, -86, 121, 64, 61, -120, -75, -63, -67, -105, -92, 85, -67, 93, 120, 34, -67, -54, 12, -28, -68, 23, 43, 16, -67, -120, 89, 47, -68, 56, 126, 15, 62, -18, 42, -99, 60, -11, 52, 28, 61, -84, 123, 118, -67, 117, 36, 16, 62, -59, 28, -61, 61, -95, 122, 102, 61, 60, 38, -99, 61, -38, -80, 32, -68, 118, 69, -65, -67, -7, -33, 9, 61, 9, 36, -13, 61, -61, -87, -66, 61, 112, 114, -124, 61, 29, 112, -111, -67, -39, 91, 0, -66, 121, -38, -55, -67, -63, 11, 4, 61, -51, 89, -115, -67, 28, -74, 58, 60, 14, 122, -105, -67, 84, 108, 5, -66, -91, 35, -41, 61, 100, 13, -38, 61, -33, 125, 85, -68, 93, 25, -111, -67, 107, -30, 37, -67, 63, -117, 57, 60, -1, 68, 48, 61, -115, 5, -120, 61, -26, 50, -103, 60, -60, 39, -122, 61, 84, 117, -71, -69, 29, 98, 110, 61, 54, 108, -67, -67, -115, -125, -111, 61, -117, 91, -99, 60, 68, -79, -112, -67, 16, -67, -122, -68, 62, -26, -8, 60, -57, 79, 105, -68, 7, 8, 48, -67, 41, 9, 123, 61, -29, -61, -97, -69, -95, 84, 114, -67, -45, 11, -6, -68, -90, -107, -90, -68, 119, -122, 82, -67, -58, -71, -122, 60, -42, -102, 120, 60, 56, 58, 105, -67, 32, -99, -49, 61, -67, 108, 56, 60";

String[] test01 = data.split(", ");
System.out.println("===============原始数据====================");
System.out.println(Arrays.toString(test01));


//对byte[]进行赋值
int size = test01.length;
byte[] demo = new byte[size];

for (int i=0;i<size;i++){
demo[i] = Byte.parseByte(test01[i]);
}

System.out.println("================存放好的数据==================");
System.out.println(Arrays.toString(demo));

结果

1
2
3
4
5
===============原始数据====================
[0, -128, -6, 68, 0, 0, -96, 65, 11, -80, -119, 61, -75, -91, 56, -69, 6, 119, 23, 62, -14, 33, -43, -67, -35, -127, 45, -68, -104, -2, 82, -67, -68, -121, 91, -68, 102, 92, -93, -67, 52, 9, -123, -67, -125, -37, 95, 61, -6, 103, 40, -67, 33, 115, 50, -68, -37, 28, -34, -67, -61, 100, -76, 61, -40, -54, -85, -67, -104, 107, -50, 61, 46, -52, -116, 61, -21, -53, -78, -67, 26, 19, -34, 61, -104, -53, -96, 61, -82, -64, -95, 60, -4, -55, -67, -67, 120, -89, 106, -67, -37, 72, -17, -68, -16, -19, -55, 60, 30, 123, -19, 61, 119, -28, -63, -67, 53, -90, -72, -67, -2, -32, -6, 60, 96, -69, -67, 61, -61, -64, 48, 61, -9, -123, -117, -68, 75, -106, 41, -67, 70, 107, -21, 60, 60, 116, 37, -67, -3, -124, 6, -70, -8, 66, -20, -69, -39, 75, 108, -68, -27, 103, -72, -67, -17, 73, 73, -67, 37, 114, 64, 61, 26, 25, -80, -67, -90, -71, 97, 61, -28, -77, -20, 61, 66, -111, -59, -70, -98, -6, -88, -68, 119, -42, -37, 60, 37, -92, -90, 60, -50, -94, 39, -66, 0, -69, -107, -68, -13, 64, -42, 61, 60, -103, -121, 61, 106, 118, -1, 61, 60, -82, -127, -67, -69, 21, -84, -68, 14, -2, 18, 61, 22, -36, 0, -68, 71, -33, -62, 61, 123, 21, -55, 60, -126, -60, 41, 61, -124, -79, -60, -71, 65, 85, -93, -67, 48, 105, -101, 59, -116, 118, -42, -68, -39, -54, -84, 59, -28, 33, 73, 61, 79, -71, -9, -67, 6, -66, 65, 61, -79, -66, -8, -67, -99, -42, -123, 61, 27, 61, 50, -67, -118, -89, 41, 61, -90, 76, -2, 61, 78, 107, 35, -66, 57, 80, -107, 61, -124, 77, 30, -67, 82, -25, 123, -67, 1, -85, -105, -67, 66, -29, 54, 60, -39, 77, -65, -69, 64, -89, -29, -68, 78, 77, 56, -67, -8, -82, -98, 60, 83, 51, 115, 61, 37, -62, 27, -67, 70, -89, -122, -67, 0, 14, -43, -68, -7, -71, 15, 62, 5, -26, 53, 60, 74, -19, -58, -67, 52, -22, 2, 61, 89, -18, -36, -69, -77, 86, 82, -67, -36, -81, 52, 60, 49, -115, 124, 61, -30, 116, -62, -67, 29, 116, 25, 61, -20, -47, 43, -67, -10, -120, 3, -66, -38, -28, 0, -66, 67, 78, 42, -67, -75, 83, -32, -68, -102, 87, -97, -67, -112, -81, 80, 59, -76, -39, 94, 61, 66, 106, 16, -67, 1, -104, 37, 60, -105, 84, -36, 61, -78, -76, -37, -67, 60, 0, 84, 58, -82, -76, -112, -67, -105, -18, 25, 61, -18, 94, -120, -68, 84, 35, -69, 61, 15, 36, -128, -69, 103, 122, 54, 60, -98, 30, -123, 61, 34, 125, 13, 62, -2, -60, -123, 61, 6, 49, -121, 61, -93, 25, -71, 60, 31, -124, 109, -67, -24, 97, 75, -67, 26, 40, -117, 61, 102, 36, -107, 61, -39, 87, 100, -67, 64, -64, 18, 61, -87, 110, -126, 60, -62, -24, 15, -67, -122, 106, -127, 61, 35, -4, -51, 61, -40, -81, 55, -67, -111, -5, 43, -68, 65, -51, 2, -66, -13, 60, 45, 61, -108, -109, -6, -68, -73, 53, 21, -67, -68, 36, -58, -67, -112, -83, 1, 61, -98, 45, -5, -67, -61, -59, -63, 61, 82, -107, 27, 61, -20, 2, -109, 61, -37, 56, 26, -67, 106, -119, -33, -68, -7, 75, -14, 58, 64, -76, 3, -67, 41, -35, 38, -67, -51, -24, 60, -68, 44, 67, 11, -67, 87, 103, 108, 60, -12, -5, 84, 61, -2, 70, 48, 61, -54, 41, -67, -68, 16, 107, -85, -68, -21, -29, -14, -67, 61, -107, 6, -66, -56, -74, -40, -67, -77, 30, -17, -68, -61, -56, -85, 60, -79, 81, -120, -67, -5, -45, 108, -67, 102, -54, -71, 60, 82, 62, 4, 61, -107, -12, 80, 61, 93, 20, -99, -68, -92, 104, 97, 59, -24, -76, 5, -67, -29, -13, 44, 61, -95, -93, -44, -68, 82, -108, 25, -67, -101, 93, 53, 60, -119, -59, 11, 61, 11, 67, -38, 60, 93, -107, -123, 60, 9, -18, 29, -67, -24, -33, -84, 61, 5, -47, -116, -67, 38, -97, -62, -67, 101, -26, 30, 60, -79, 85, -66, 61, -64, 76, -8, 60, -110, -112, -126, 58, 32, -5, -1, 59, -67, -105, 15, -66, -126, -23, -77, 61, -95, -37, 33, 60, -44, -80, -9, -69, -59, -15, -101, -67, 52, -27, -82, 60, 94, 100, 6, -68, -58, -79, 114, -68, -109, 16, 48, 61, -94, -106, 0, -67, 86, -42, -22, -68, -96, 107, -92, -67, -86, 121, 64, 61, -120, -75, -63, -67, -105, -92, 85, -67, 93, 120, 34, -67, -54, 12, -28, -68, 23, 43, 16, -67, -120, 89, 47, -68, 56, 126, 15, 62, -18, 42, -99, 60, -11, 52, 28, 61, -84, 123, 118, -67, 117, 36, 16, 62, -59, 28, -61, 61, -95, 122, 102, 61, 60, 38, -99, 61, -38, -80, 32, -68, 118, 69, -65, -67, -7, -33, 9, 61, 9, 36, -13, 61, -61, -87, -66, 61, 112, 114, -124, 61, 29, 112, -111, -67, -39, 91, 0, -66, 121, -38, -55, -67, -63, 11, 4, 61, -51, 89, -115, -67, 28, -74, 58, 60, 14, 122, -105, -67, 84, 108, 5, -66, -91, 35, -41, 61, 100, 13, -38, 61, -33, 125, 85, -68, 93, 25, -111, -67, 107, -30, 37, -67, 63, -117, 57, 60, -1, 68, 48, 61, -115, 5, -120, 61, -26, 50, -103, 60, -60, 39, -122, 61, 84, 117, -71, -69, 29, 98, 110, 61, 54, 108, -67, -67, -115, -125, -111, 61, -117, 91, -99, 60, 68, -79, -112, -67, 16, -67, -122, -68, 62, -26, -8, 60, -57, 79, 105, -68, 7, 8, 48, -67, 41, 9, 123, 61, -29, -61, -97, -69, -95, 84, 114, -67, -45, 11, -6, -68, -90, -107, -90, -68, 119, -122, 82, -67, -58, -71, -122, 60, -42, -102, 120, 60, 56, 58, 105, -67, 32, -99, -49, 61, -67, 108, 56, 60]
================存放好的数据==================
[0, -128, -6, 68, 0, 0, -96, 65, 11, -80, -119, 61, -75, -91, 56, -69, 6, 119, 23, 62, -14, 33, -43, -67, -35, -127, 45, -68, -104, -2, 82, -67, -68, -121, 91, -68, 102, 92, -93, -67, 52, 9, -123, -67, -125, -37, 95, 61, -6, 103, 40, -67, 33, 115, 50, -68, -37, 28, -34, -67, -61, 100, -76, 61, -40, -54, -85, -67, -104, 107, -50, 61, 46, -52, -116, 61, -21, -53, -78, -67, 26, 19, -34, 61, -104, -53, -96, 61, -82, -64, -95, 60, -4, -55, -67, -67, 120, -89, 106, -67, -37, 72, -17, -68, -16, -19, -55, 60, 30, 123, -19, 61, 119, -28, -63, -67, 53, -90, -72, -67, -2, -32, -6, 60, 96, -69, -67, 61, -61, -64, 48, 61, -9, -123, -117, -68, 75, -106, 41, -67, 70, 107, -21, 60, 60, 116, 37, -67, -3, -124, 6, -70, -8, 66, -20, -69, -39, 75, 108, -68, -27, 103, -72, -67, -17, 73, 73, -67, 37, 114, 64, 61, 26, 25, -80, -67, -90, -71, 97, 61, -28, -77, -20, 61, 66, -111, -59, -70, -98, -6, -88, -68, 119, -42, -37, 60, 37, -92, -90, 60, -50, -94, 39, -66, 0, -69, -107, -68, -13, 64, -42, 61, 60, -103, -121, 61, 106, 118, -1, 61, 60, -82, -127, -67, -69, 21, -84, -68, 14, -2, 18, 61, 22, -36, 0, -68, 71, -33, -62, 61, 123, 21, -55, 60, -126, -60, 41, 61, -124, -79, -60, -71, 65, 85, -93, -67, 48, 105, -101, 59, -116, 118, -42, -68, -39, -54, -84, 59, -28, 33, 73, 61, 79, -71, -9, -67, 6, -66, 65, 61, -79, -66, -8, -67, -99, -42, -123, 61, 27, 61, 50, -67, -118, -89, 41, 61, -90, 76, -2, 61, 78, 107, 35, -66, 57, 80, -107, 61, -124, 77, 30, -67, 82, -25, 123, -67, 1, -85, -105, -67, 66, -29, 54, 60, -39, 77, -65, -69, 64, -89, -29, -68, 78, 77, 56, -67, -8, -82, -98, 60, 83, 51, 115, 61, 37, -62, 27, -67, 70, -89, -122, -67, 0, 14, -43, -68, -7, -71, 15, 62, 5, -26, 53, 60, 74, -19, -58, -67, 52, -22, 2, 61, 89, -18, -36, -69, -77, 86, 82, -67, -36, -81, 52, 60, 49, -115, 124, 61, -30, 116, -62, -67, 29, 116, 25, 61, -20, -47, 43, -67, -10, -120, 3, -66, -38, -28, 0, -66, 67, 78, 42, -67, -75, 83, -32, -68, -102, 87, -97, -67, -112, -81, 80, 59, -76, -39, 94, 61, 66, 106, 16, -67, 1, -104, 37, 60, -105, 84, -36, 61, -78, -76, -37, -67, 60, 0, 84, 58, -82, -76, -112, -67, -105, -18, 25, 61, -18, 94, -120, -68, 84, 35, -69, 61, 15, 36, -128, -69, 103, 122, 54, 60, -98, 30, -123, 61, 34, 125, 13, 62, -2, -60, -123, 61, 6, 49, -121, 61, -93, 25, -71, 60, 31, -124, 109, -67, -24, 97, 75, -67, 26, 40, -117, 61, 102, 36, -107, 61, -39, 87, 100, -67, 64, -64, 18, 61, -87, 110, -126, 60, -62, -24, 15, -67, -122, 106, -127, 61, 35, -4, -51, 61, -40, -81, 55, -67, -111, -5, 43, -68, 65, -51, 2, -66, -13, 60, 45, 61, -108, -109, -6, -68, -73, 53, 21, -67, -68, 36, -58, -67, -112, -83, 1, 61, -98, 45, -5, -67, -61, -59, -63, 61, 82, -107, 27, 61, -20, 2, -109, 61, -37, 56, 26, -67, 106, -119, -33, -68, -7, 75, -14, 58, 64, -76, 3, -67, 41, -35, 38, -67, -51, -24, 60, -68, 44, 67, 11, -67, 87, 103, 108, 60, -12, -5, 84, 61, -2, 70, 48, 61, -54, 41, -67, -68, 16, 107, -85, -68, -21, -29, -14, -67, 61, -107, 6, -66, -56, -74, -40, -67, -77, 30, -17, -68, -61, -56, -85, 60, -79, 81, -120, -67, -5, -45, 108, -67, 102, -54, -71, 60, 82, 62, 4, 61, -107, -12, 80, 61, 93, 20, -99, -68, -92, 104, 97, 59, -24, -76, 5, -67, -29, -13, 44, 61, -95, -93, -44, -68, 82, -108, 25, -67, -101, 93, 53, 60, -119, -59, 11, 61, 11, 67, -38, 60, 93, -107, -123, 60, 9, -18, 29, -67, -24, -33, -84, 61, 5, -47, -116, -67, 38, -97, -62, -67, 101, -26, 30, 60, -79, 85, -66, 61, -64, 76, -8, 60, -110, -112, -126, 58, 32, -5, -1, 59, -67, -105, 15, -66, -126, -23, -77, 61, -95, -37, 33, 60, -44, -80, -9, -69, -59, -15, -101, -67, 52, -27, -82, 60, 94, 100, 6, -68, -58, -79, 114, -68, -109, 16, 48, 61, -94, -106, 0, -67, 86, -42, -22, -68, -96, 107, -92, -67, -86, 121, 64, 61, -120, -75, -63, -67, -105, -92, 85, -67, 93, 120, 34, -67, -54, 12, -28, -68, 23, 43, 16, -67, -120, 89, 47, -68, 56, 126, 15, 62, -18, 42, -99, 60, -11, 52, 28, 61, -84, 123, 118, -67, 117, 36, 16, 62, -59, 28, -61, 61, -95, 122, 102, 61, 60, 38, -99, 61, -38, -80, 32, -68, 118, 69, -65, -67, -7, -33, 9, 61, 9, 36, -13, 61, -61, -87, -66, 61, 112, 114, -124, 61, 29, 112, -111, -67, -39, 91, 0, -66, 121, -38, -55, -67, -63, 11, 4, 61, -51, 89, -115, -67, 28, -74, 58, 60, 14, 122, -105, -67, 84, 108, 5, -66, -91, 35, -41, 61, 100, 13, -38, 61, -33, 125, 85, -68, 93, 25, -111, -67, 107, -30, 37, -67, 63, -117, 57, 60, -1, 68, 48, 61, -115, 5, -120, 61, -26, 50, -103, 60, -60, 39, -122, 61, 84, 117, -71, -69, 29, 98, 110, 61, 54, 108, -67, -67, -115, -125, -111, 61, -117, 91, -99, 60, 68, -79, -112, -67, 16, -67, -122, -68, 62, -26, -8, 60, -57, 79, 105, -68, 7, 8, 48, -67, 41, 9, 123, 61, -29, -61, -97, -69, -95, 84, 114, -67, -45, 11, -6, -68, -90, -107, -90, -68, 119, -122, 82, -67, -58, -71, -122, 60, -42, -102, 120, 60, 56, 58, 105, -67, 32, -99, -49, 61, -67, 108, 56, 60]

获得对比图片的人信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//初始化引擎
EngineConfiguration engineConfiguration = new EngineConfiguration();

//检测模式设置
//这里因为我们是对图片进行人脸识别,因此这里我们使用一个IMAGE模式
engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);

//可检测图片人脸方向设置
engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_ALL_OUT);//这里我设置的是全方位角设置
engineConfiguration.setDetectFaceMaxNum(40);//最大识别人脸数量
engineConfiguration.setDetectFaceScaleVal(16);//识别等级

//设置引擎功能
//功能配置,可以设置面容识别时是否分析年龄、性别、3d等。
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("引擎初始化失败");
}


System.out.println("=================以下是aaa.jpg的数据========================");

//图片所在的文件路径
String fileUrl = "D:\\AreFace\\AreFaceTest\\";
//文件名称
String fileName = "aaa.jpg";
File file1 = new File(fileUrl + fileName);
ImageInfo imageInfo = getRGBData(file1);
//获得一个图片里的所有人脸信息
List<FaceInfo> faceInfos = new ArrayList<>();

faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(),imageInfo.getHeight() ,imageInfo.getImageFormat(),faceInfos);



//获得feature
FaceFeature faceFeature1 = new FaceFeature();
faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(),imageInfo.getHeight() ,imageInfo.getImageFormat(),faceInfos.get(0),faceFeature1);

//输出特征值
System.out.println(Arrays.toString(faceFeature1.getFeatureData()));

调用方法进行对比获得相似度

1
2
3
4
5
//调用程序 通过对比faceFeature 获得脸部信息的相似度
FaceSimilar faceSimilar = new FaceSimilar();
faceEngine.compareFaceFeature(faceFeature,faceFeature1,faceSimilar);
//输出相似度 大抵应该是1
System.out.println(faceSimilar.getScore());

这种方法的结果

xWvDEt.png

正常两张图片对比的结果

xWvrUP.png

一模一样 可以说是成功了

人脸识别类型

根据官网介绍,人脸识别大致可以分为两种

  • 你是谁 (一对多)
  • 你是不是照片上这个人(一对一)

对于“你是谁”问题

“你是谁”在我的想法里,是一个一对多的过程,很多人的照片faceFeature存储在一个数据库中,当有人上传了他的照片,到数据库中找数据,查找到相似度最高且超过阈值的人,认为是查找到的人。

阈值:即相似度,对于这个相似度的把控,我还没有查询到资料,不知道多少合适暂定为0.9

对于”是不是你”问题

这个问题很明显是一个一对一问题,而且很好操作,是一对多题的简化。

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

扫一扫,分享到微信

微信分享二维码
  • Copyrights © 2015-2023 dwx
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信