密钥信息:C V替换到代码中即可
SecretId: AKIDiAPRPExObXBZoxFr0tBED0ayDDwc7nLq
SecretKey: vc2MsEQZVffZMEpxoPwiIcgYFfuzmIft
1、新增人员,录入人脸信息
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.iai.v20200303.IaiClient;
import com.tencentcloudapi.iai.v20200303.models.*;
public class CreatePerson
{
public static void main(String [] args) {
try{
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
Credential cred = new Credential("SecretId", "SecretKey");
// 实例化一个http选项,可选的,没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("iai.tencentcloudapi.com");
// 实例化一个client选项,可选的,没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
// 实例化要请求产品的client对象,clientProfile是可选的
IaiClient client = new IaiClient(cred, "ap-beijing", clientProfile);
// 实例化一个请求对象,每个接口都会对应一个request对象
CreatePersonRequest req = new CreatePersonRequest();
req.setGroupId("2108");//固定(由后台创建)
req.setPersonName("李永涛");//人员姓名
req.setPersonId("002");//人员ID,不可重复
req.setGender(1);//1男,2女
req.setImage("照片");//图片 base64 数据,base64 编码后大小不可超过5M。 jpg格式长边像素不可超过4000,其他格式图片长边像素不可超2000。 支持PNG、JPG、JPEG、BMP,不支持 GIF 图片。
// 返回的resp是一个CreatePersonResponse的实例,与请求对象对应
CreatePersonResponse resp = client.CreatePerson(req);
// 输出json格式的字符串回包
System.out.println(CreatePersonResponse.toJsonString(resp));
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}
}
}
添加成功的响应结果
{
"Response": {
"FaceId": "4415956956572855082",
"SimilarPersonId": "",
"FaceRect": {
"X": 362,
"Y": 289,
"Width": 414,
"Height": 564
},
"FaceModelVersion": "3.0",
"RequestId": "32064be1-b439-4943-b49e-a51bf6ac1aa5"
}
}
2、通过人员ID获取信息
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.iai.v20200303.IaiClient;
import com.tencentcloudapi.iai.v20200303.models.*;
public class GetPersonBaseInfo
{
public static void main(String [] args) {
try{
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
Credential cred = new Credential("SecretId", "SecretKey");
// 实例化一个http选项,可选的,没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("iai.tencentcloudapi.com");
// 实例化一个client选项,可选的,没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
// 实例化要请求产品的client对象,clientProfile是可选的
IaiClient client = new IaiClient(cred, "ap-beijing", clientProfile);
// 实例化一个请求对象,每个接口都会对应一个request对象
GetPersonBaseInfoRequest req = new GetPersonBaseInfoRequest();
req.setPersonId("001");//人员ID
// 返回的resp是一个GetPersonBaseInfoResponse的实例,与请求对象对应
GetPersonBaseInfoResponse resp = client.GetPersonBaseInfo(req);
// 输出json格式的字符串回包
System.out.println(GetPersonBaseInfoResponse.toJsonString(resp));
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}
}
}
响应结果:
{
"Response": {
"PersonName": "李永涛",
"Gender": 1,
"FaceIds": [
"4415937851716335376"
],
"RequestId": "45e7c146-da75-480c-81f1-563b3a2c6134"
}
}
3、人脸静态活体检测高精度版(验证是照片还是真人,根据返回Score进行判断,Score的值越大,说明是真人,取值为整数,范围0~100)
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.iai.v20200303.IaiClient;
import com.tencentcloudapi.iai.v20200303.models.*;
public class DetectLiveFaceAccurate
{
public static void main(String [] args) {
try{
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
Credential cred = new Credential("SecretId", "SecretKey");
// 实例化一个http选项,可选的,没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("iai.tencentcloudapi.com");
// 实例化一个client选项,可选的,没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
// 实例化要请求产品的client对象,clientProfile是可选的
IaiClient client = new IaiClient(cred, "ap-beijing", clientProfile);
// 实例化一个请求对象,每个接口都会对应一个request对象
DetectLiveFaceAccurateRequest req = new DetectLiveFaceAccurateRequest();
req.setImage("图片");//base64编码格式
// 返回的resp是一个DetectLiveFaceAccurateResponse的实例,与请求对象对应
DetectLiveFaceAccurateResponse resp = client.DetectLiveFaceAccurate(req);
// 输出json格式的字符串回包
System.out.println(DetectLiveFaceAccurateResponse.toJsonString(resp));
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}
}
}
响应结果:
{
"Response": {
"Score": 78,//返回比分
"FaceModelVersion": "3.0",
"RequestId": "21990b7d-1e82-4ca2-a565-667e439eaa9b"
}
}
4、人员验证(人脸识别验证)
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.iai.v20200303.IaiClient;
import com.tencentcloudapi.iai.v20200303.models.*;
public class VerifyPerson
{
public static void main(String [] args) {
try{
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
Credential cred = new Credential("SecretId", "SecretKey");
// 实例化一个http选项,可选的,没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("iai.tencentcloudapi.com");
// 实例化一个client选项,可选的,没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
// 实例化要请求产品的client对象,clientProfile是可选的
IaiClient client = new IaiClient(cred, "ap-beijing", clientProfile);
// 实例化一个请求对象,每个接口都会对应一个request对象
VerifyPersonRequest req = new VerifyPersonRequest();
req.setImage("图片");//base64编码
req.setPersonId("001");//人员ID
// 返回的resp是一个VerifyPersonResponse的实例,与请求对象对应
VerifyPersonResponse resp = client.VerifyPerson(req);
// 输出json格式的字符串回包
System.out.println(VerifyPersonResponse.toJsonString(resp));
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}
}
}
响应结果
{
"Response": {
"Score": 100,//相似度
"IsMatch": true,//true为匹配成功,false匹配失败
"FaceModelVersion": "3.0",
"RequestId": "91c00dff-4267-489c-a508-8ee939cc7430"
}
}
其他:人脸识别功能很多,上面是常用的几个,还需要其他功能需求的,单独给你们发。