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

SDK接口示例

分享
更新时间: 2020/07/27 GMT+08:00

V1版本SDK示例

  1. 构造服务客户端
    1
    2
    3
    4
    5
    6
    7
    8
    9
    ak = "ak"
    sk = "sk"
    project_id = "projectId"
    end_point = "https://face.cn-north-4.myhuaweicloud.com"
    proxy = {"http": "http://127.0.0.1:1234",
    "https": "http://127.0.0.1:1234"}
    auth_info = AuthInfo(ak=ak, sk=sk, end_point=end_point)
    frs_client = FrsClient(auth_info=auth_info, project_id=project_id)
    # frs_client = FrsClient(auth_info=auth_info, project_id=project_id, proxies=proxy) #当您需要代理才可以访问到服务时,在第三个参数增加代理信息即可
    
  2. 创建人脸集
    1
    2
    3
    fss = frs_client.get_face_set_service()
    external_fields = {"timestamp": {"type": "long"}, "id": {"type": "string"}, "number": {"type": "integer"}}
    ret = fss.create_face_set("faceSetName", 10000, external_fields)
    
  3. 添加人脸
    1
    2
    3
    fs = frsClient.get_face_service()
    external_fields = {"timestamp": 12,"id": "home"}
    res = fs.add_face_by_obs_url("faceSetName", "/obs/image.jpg", "externalImageId", external_fields)
    
  4. 人脸检测
    1
    2
    ds = frs.get_detect_service()
    res = ds.detect_face_by_file("imagePath", "0,1,2,3")
    

V2版本SDK示例

  1. 构造服务客户端
    1
    2
    3
    4
    5
    6
    7
    8
    9
    ak = "ak"
    sk = "sk"
    project_id = "projectId"
    end_point = "https://face.cn-north-4.myhuaweicloud.com"
    proxy = {"http": "http://127.0.0.1:1234",
    "https": "http://127.0.0.1:1234"}
    auth_info = AuthInfo(ak=ak, sk=sk, end_point=end_point)
    frs_client = FrsClient(auth_info=auth_info, project_id=project_id)
    # frs_client = FrsClient(auth_info=auth_info, project_id=project_id, proxies=proxy) #当您需要代理才可以访问到服务时,在第三个参数增加代理信息即可
    
  2. 创建人脸集
    1
    2
    3
    fss = frs_client.get_v2().get_face_set_service()
    external_fields = {"timestamp":{"type" : "long"},"id":{"type":"string"},"number":{"type":"integer"}}
    ret = fss.create_face_set("faceSetName", 10000, external_fields)
    
  3. 添加人脸
    1
    2
    3
    fs = frsClient.get_v2().get_face_service()
    external_fields = {"timestamp": 12,"id": "home"}
    res = fs.add_face_by_obs_url("faceSetName", "/obs/image.jpg", "externalImageId", external_fields)
    
  4. 人脸检测
    1
    2
    ds = frs.get_v2().get_detect_service()
    res = ds.detect_face_by_file("imagePath", "1,2")
    
分享:

    相关文档

    相关产品

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

提交成功!

非常感谢您的反馈,我们会继续努力做到更好!

反馈提交失败,请稍后再试!

*必选

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

字符长度不能超过200

提交反馈 取消

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

智能客服提问云社区提问