对接腾讯云 人脸识别应用

    技术2022-07-11  143

    官方地址:https://github.com/TencentCloud/tencentcloud-sdk-java

    需求:需要使用腾讯云人脸识别应用,对人脸照片的质量评分,筛选掉不清晰的照片。

    腾讯云的文档好像很久没更新了,这部分内容看的有点懵,后来从GitHub官方地址入手,很快就实现了。

    个人对接步骤:

    导入maven依赖:

    <dependency> <groupId>com.tencentcloudapi</groupId> <artifactId>tencentcloud-sdk-java</artifactId> <!-- go to https://search.maven.org/search?q=tencentcloud-sdk-java and get the latest version. --> <!-- 请到https://search.maven.org/search?q=tencentcloud-sdk-java查询最新版本 --> <version>3.1.81</version> </dependency>

    按照官方demo写:

    import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.exception.TencentCloudSDKException; import com.tencentcloudapi.common.profile.ClientProfile; import com.tencentcloudapi.iai.v20200303.IaiClient; import com.tencentcloudapi.iai.v20200303.models.*; Credential credential = new Credential(secretId, secretKey); ClientProfile clientProfile = new ClientProfile(); // 签名方式根据版本选择,此处版本为v20200303 clientProfile.setSignMethod(ClientProfile.SIGN_SHA256); // 第二个参数根据位置选择,华南选广州即可 IaiClient iaiClient = new IaiClient(credential, "ap-guangzhou"); try { DetectFaceRequest detectFaceRequest = new DetectFaceRequest(); // url好像不能有中文,阿里云oss的也可用 detectFaceRequest.setUrl(url); // 检测照片质量,默认0不选中 detectFaceRequest.setNeedQualityDetection((long) 1); DetectFaceResponse detectFaceResponse = iaiClient.DetectFace(detectFaceRequest); FaceInfo[] faceInfos = detectFaceResponse.getFaceInfos(); FaceInfo faceInfo = faceInfos[0]; FaceQualityInfo faceQualityInfo = faceInfo.getFaceQualityInfo(); Long score = faceQualityInfo.getScore(); // 自定义业务处理 if (defaultAvailableScore > score){ return xxx; } else { return xxx; } } catch (Exception e) { return xxx; }

     

    Processed: 0.012, SQL: 10