java腾讯云人脸识别接口

1,引入maven依赖
在这里插入图片描述
2,
public class TenXunUtil {
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
// 密钥可前https://console.cloud.tencent.com/cam/capi网站进行获取
public static String SecretId = "SecretId ";
public static String SecretKey = "SecretKey ";
//最多识别的人脸数目
public static Long MaxFaceNum = 1L;
//单张被识别的人脸返回的最相似人员数量
public static Long MaxPersonNum = 1L;
//是否返回人员具体信息。0 为关闭,1 为开启。默认为 0。其他非0非1值默认为0
public static Long NeedPersonInfo = 1L;
//地域参数
public static String Region = “ap-shanghai”;
//搜索人员库id
public static String[] groupIds={“groupIds”};
//创建人员所在库id
public static String groupId = "groupId ";
public static Long UniquePersonControl = 0L;
public static Long QualityControl = 0L;
public static Long NeedRotateDetection = 0L;
private static Credential cred;
private static HttpProfile httpProfile;
private static ClientProfile clientProfile;
private static IaiClient client;
static {
cred = new Credential(SecretId, SecretKey);
httpProfile = httpProfile = new HttpProfile();
httpProfile.setEndpoint(“iai.tencentcloudapi.com”);
clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
client = new IaiClient(cred, Region, clientProfile);
groupId=ToolUtils.getGroupId();
groupIds=new String[]{groupId};
}

/**
 * 人脸搜索
 *
 * @param url   图片的 Url
 * @param image 图片 base64 数据
 */
public static String searchFaces(String url, String image) {
    SearchFacesRequest req = new SearchFacesRequest();
    req.setGroupIds(groupIds);
    req.setImage(image);
    req.setUrl(url);
    req.setMaxFaceNum(MaxFaceNum);
    req.setMaxPersonNum(MaxPersonNum);
    req.setNeedPersonInfo(NeedPersonInfo);
    // 返回的resp是一个SearchFacesResponse的实例,与请求对象对应
    SearchFacesResponse resp = null;
    String result = "";
    try {
        resp = client.SearchFaces(req);
        result = SearchFacesResponse.toJsonString(resp);
    } catch (TencentCloudSDKException e) {
        e.printStackTrace();
    }
    return result;
}
//创建人员
public static String createPerson(Students student) {
    CreatePersonRequest req = new CreatePersonRequest();
    req.setGroupId(groupId);
    req.setPersonName(student.getStudentName());
    req.setPersonId(student.getStudentNumber());
    req.setGender(student.getSex().longValue());
    req.setUrl(student.getAvatar());
    req.setUniquePersonControl(UniquePersonControl);
    req.setQualityControl(QualityControl);
    req.setNeedRotateDetection(NeedRotateDetection);
    String result = "";
    try {
        CreatePersonResponse resp = client.CreatePerson(req);
        result = CreatePersonResponse.toJsonString(resp);
    } catch (TencentCloudSDKException e) {
        e.printStackTrace();
    }
    return result;
}
//删除人员
public static String deletePersonFromGroup(String personId){
    DeletePersonFromGroupRequest req = new DeletePersonFromGroupRequest();
    req.setPersonId(personId);
    req.setGroupId(groupId);
    // 返回的resp是一个DeletePersonFromGroupResponse的实例,与请求对象对应
    DeletePersonFromGroupResponse resp = null;
    String result="";
    try {
        resp = client.DeletePersonFromGroup(req);
        result=DeletePersonFromGroupResponse.toJsonString(resp);
    } catch (TencentCloudSDKException e) {
        e.printStackTrace();
    }
   return result;
}

}
3.参数解析(图片)
a,SecretId,SecretKey
通过https://console.cloud.tencent.com/cam/capi获取
在这里插入图片描述
b, groupId 腾讯云人脸识别后台创建人脸库
在这里插入图片描述
c,MaxFaceNum ,MaxPersonNum ,Region 等详细介绍链接
https://cloud.tencent.com/document/product/867/45023#.E4.BA.BA.E5.91.98.E5.BA.93.E7.AE.A1.E7.90.86.E7.9B.B8.E5.85.B3.E6.8E.A5.E5.8F.A3
d,Students 自定义的实体类
@Data
public class Students{
private String studentName;
private String studentNumber;
private Integer sex;
private String avatar;
}
e, personId
在这里插入图片描述
4,人脸识别相关接口代码生成
链接
https://console.cloud.tencent.com/api/explorer?Product=cvm&Version=2017-03-12&Action=DescribeZones&SignVersion=
在这里插入图片描述
5,购买资源包
在这里插入图片描述

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值