文档首页 > > SDK参考> Java SDK> SDK接口示例

SDK接口示例

分享
更新时间:2020/03/19 GMT+08:00

V1版本SDK示例

  1. 构造服务客户端
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    String ak = "ak";
    String sk = "sk";
    String projectId = "projectId";
    //Proxy info,当您需要使用代理才可以访问到服务时,可在此处增加代理信息
    ProxyHostInfo proxyHostInfo = new ProxyHostInfo("proxy",
    8080,
    "UserName",
    "Password"
    );
    //Service info
    String url = "https://face.cn-north-4.myhuaweicloud.com";
    String region = "cn-north-4";
    AuthInfo authInfo = new AuthInfo(url, region, ak, sk);
    FrsClient frsClient = new FrsClient(authInfo, projectId);
    //FrsClient frsClient = new FrsClient(authInfo, projectId, proxyHostInfo);//当您需要代理才可以访问到服务时,在第三个参数增加代理信息即可
    
  2. 创建人脸集
    1
    2
    3
    CreateExternalFields createExternalFields = new CreateExternalFields();
    createExternalFields.addField("testInteger", FieldType.INTEGER);
    CreateFaceSetResult createFaceSetResult = frsClient.getFaceSetService().createFaceSet(faceSetName, faceSetCapacity, createExternalFields);
    
  3. 添加人脸
    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.getFaceService().addFaceByBase64(faceSetName, imageId, imageBase64, addExternalFields);
    
  4. 调用人脸检测服务
    1
    2
    3
    String obsUrl = "/bucket/face.jpg";
    String attr = "0,1,2,3,4,5";
    DetectFaceResult detectFaceResult = frsClient.getDetectService().detectFaceByObsUrl(obsUrl, attr);
    

V2版本SDK示例

  1. 构造服务客户端
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    String ak = "ak";
    String sk = "sk";
    String projectId = "projectId";
    //Proxy info,当您需要使用代理才可以访问到服务时,可在此处增加代理信息
    ProxyHostInfo proxyHostInfo = new ProxyHostInfo("proxy",
    8080,
    "UserName",
    "Password"
    );
    //Service info
    String url = "https://face.cn-north-4.myhuaweicloud.com";
    String region = "cn-north-4";
    AuthInfo authInfo = new AuthInfo(url, region, ak, sk);
    FrsClient frsClient = new FrsClient(authInfo, projectId);
    //FrsClient frsClient = new FrsClient(authInfo, projectId, proxyHostInfo);//当您需要代理才可以访问到服务时,在第三个参数增加代理信息即可
    
  2. 创建人脸集
    1
    2
    3
    CreateExternalFields createExternalFields = new CreateExternalFields();
    createExternalFields.addField("testInteger", FieldType.INTEGER);
    CreateFaceSetResult createFaceSetResult = frsClient.getV2().getFaceSetService().createFaceSet(faceSetName, faceSetCapacity, createExternalFields);
    
  3. 添加人脸
    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);
    
  4. 调用人脸检测服务
    1
    2
    3
    String obsUrl = "/bucket/face.jpg";
    String attr = "1,2";
    DetectFaceResult detectFaceResult = frsClient.getV2().getDetectService().detectFaceByObsUrl(obsUrl, attr);
    
分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!非常感谢您的反馈,我们会继续努力做到更好!
反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

智能客服提问云社区提问