更新时间:2024-03-05 GMT+08:00
SDK接口示例
SDK示例
- 构造服务客户端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
String ak = System.getenv("HUAWEICLOUD_SDK_AK"); String sk = System.getenv("HUAWEICLOUD_SDK_SK"); String projectId = "projectId"; //Proxy info,当您需要使用代理才可以访问到服务时,可在此处增加代理信息 ProxyHostInfo proxyHostInfo = new ProxyHostInfo("proxy", 8080, "UserName", "Password" ); //Service info String url = "https://face.ap-southeast-1.myhuaweicloud.com"; String region = "ap-southeast-1"; AuthInfo authInfo = new AuthInfo(url, region, ak, sk); FrsClient frsClient = new FrsClient(authInfo, projectId); //FrsClient frsClient = new FrsClient(authInfo, projectId, proxyHostInfo);//当您需要代理才可以访问到服务时,在第三个参数增加代理信息即可
- 创建人脸集
1 2 3
CreateExternalFields createExternalFields = new CreateExternalFields(); createExternalFields.addField("testInteger", FieldType.INTEGER); CreateFaceSetResult createFaceSetResult = frsClient.getV2().getFaceSetService().createFaceSet(faceSetName, faceSetCapacity, createExternalFields);
- 添加人脸
1 2 3 4 5 6 7
String imageId = "image1"; File image = new File("data/face.jpg"); byte[] fileData = FileUtils.readFileToByteArray(image); String imageBase64 = Base64.encodeBase64String(fileData); AddExternalFields addExternalFields = new AddExternalFields(); addExternalFields.addField("testInteger", 123); AddFaceResult addFaceResult = frsClient.getV2().getFaceService().addFaceByBase64(faceSetName, imageId, imageBase64, addExternalFields);
- 调用人脸检测服务
1 2 3
String obsUrl = "/bucket/face.jpg"; String attr = "1,2"; DetectFaceResult detectFaceResult = frsClient.getV2().getDetectService().detectFaceByObsUrl(obsUrl, attr);
父主题: Java SDK