52 lines
2.1 KiB
Java
52 lines
2.1 KiB
Java
package com.zcloud.util;
|
|
|
|
import com.aliyuncs.DefaultAcsClient;
|
|
import com.aliyuncs.IAcsClient;
|
|
import com.aliyuncs.facebody.model.v20191230.CompareFaceRequest;
|
|
import com.aliyuncs.facebody.model.v20191230.CompareFaceResponse;
|
|
import com.aliyuncs.profile.DefaultProfile;
|
|
|
|
/**
|
|
* @author fangjiakai
|
|
* @date 2021/11/26 9:11
|
|
*/
|
|
public class FaceUtil {
|
|
private static final String ACCESS_KEY_ID = "LTAI5tK134ZzXPEwykAdpVn2";
|
|
private static final String ACCESS_KEY_SECRET = "XCEMY8FG52cXImFMeIiH4tDJ9BIN3N";
|
|
|
|
public static String compareFace(String data1, String data2) throws Exception{
|
|
DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", ACCESS_KEY_ID, ACCESS_KEY_SECRET);
|
|
IAcsClient client = new DefaultAcsClient(profile);
|
|
|
|
CompareFaceRequest request = new CompareFaceRequest();
|
|
request.setImageDataA(data1);
|
|
request.setImageDataB(data2);
|
|
CompareFaceResponse response = client.getAcsResponse(request);
|
|
|
|
return response.getData().getConfidence().toString();//大于75则
|
|
}
|
|
|
|
|
|
// public static void main(String[] args_) throws Exception {
|
|
// DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", ACCESS_KEY_ID, ACCESS_KEY_SECRET);
|
|
// IAcsClient client = new DefaultAcsClient(profile);
|
|
//
|
|
// CompareFaceRequest request = new CompareFaceRequest();
|
|
// request.setImageDataA( ImageAnd64Binary.getImageStr("C:\\Users\\Administrator\\Desktop\\测试用图\\QQ截图20211202153748.png"));
|
|
// request.setImageDataB( ImageAnd64Binary.getImageStr("C:\\Users\\Administrator\\Desktop\\测试用图\\QQ截图20211202153933.png"));
|
|
// try {
|
|
// CompareFaceResponse response = client.getAcsResponse(request);
|
|
// System.out.println(new Gson().toJson(response));
|
|
// } catch (ServerException e) {
|
|
// e.printStackTrace();
|
|
// } catch (ClientException e) {
|
|
// System.out.println("ErrCode:" + e.getErrCode());
|
|
// System.out.println("ErrMsg:" + e.getErrMsg());
|
|
// System.out.println("RequestId:" + e.getRequestId());
|
|
// }
|
|
// }
|
|
|
|
public static void main(String[] args) {
|
|
}
|
|
}
|