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

SDK接口示例

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

V1版本SDK示例

  1. 构造服务客户端
    authInfo := param.AuthInfo{EndPoint: "https://face.cn-north-4.myhuaweicloud.com", Ak: "ak", Sk: "sk"}
    frsClient := service.NewFrsClient(&authInfo, "projectId")
    //proxyInfo := param.ProxyHostInfo{Proxy: "http://127.0.0.1:8080"} 
    //frsClient := service.NewFrsClientWithProxy(&authInfo, "projectId", &proxyInfo)//当您需要代理才可以访问到服务时,在第三个参数增加代理信息即可
  2. 创建人脸集
    externalFields := param.NewCreateExternalFields()
    externalFields.AddField("testInteger", param.INTEGER)
    result, err := frsClient.GetFaceSetService().CreateFaceSetWithExtFields("FaceSetName", 10000, externalFields)
    if nil != err {
    fmt.Println(err.Error())
    } else {
    fmt.Println(result)
    }
  3. 添加人脸
    externalFields := param.NewAddExternalFields()
    externalFields.AddField("testInteger", 123)
    result, err := frsClient.GetFaceService().AddFaceByFileFull("faceSetName", "externalImageId", "imagePath", externalFields)
    if nil != err {
    fmt.Println(err.Error())
    } else {
    fmt.Println(result)
    }
  4. 人脸检测
    detectResult, err := frsClient.GetDetectService().DetectFaceByObsUrlWithAttr("/obs/image.jpg", "0,1,2")
    if nil != err {
    fmt.Println(err.Error())
    } else {
    fmt.Println(detectResult)
    }

V2版本SDK示例

  1. 构造服务客户端
    authInfo := param.AuthInfo{EndPoint: "https://face.cn-north-4.myhuaweicloud.com", Ak: "ak", Sk: "sk"}
    frsClient := service.NewFrsClient(&authInfo, "projectId")
    //proxyInfo := param.ProxyHostInfo{Proxy: "http://127.0.0.1:8080"} 
    //frsClient := service.NewFrsClientWithProxy(&authInfo, "projectId", &proxyInfo)//当您需要代理才可以访问到服务时,在第三个参数增加代理信息即可
  2. 创建人脸集
    externalFields := param.NewCreateExternalFields()
    externalFields.AddField("testInteger", param.INTEGER)
    result, err := frsClient.GetV2().GetFaceSetService().CreateFaceSetWithExtFields("FaceSetName", 10000, externalFields)
    if nil != err {
    fmt.Println(err.Error())
    } else {
    fmt.Println(result)
    }
  3. 添加人脸
    externalFields := param.NewAddExternalFields()
    externalFields.AddField("testInteger", 123)
    result, err := frsClient.GetV2().GetFaceService().AddFaceByFileFull("faceSetName", "externalImageId", "imagePath", externalFields)
    if nil != err {
    fmt.Println(err.Error())
    } else {
    fmt.Println(result)
    }
  4. 人脸检测
    detectResult, err := frsClient.GetV2().GetDetectService().DetectFaceByObsUrlWithAttr("/obs/image.jpg", "0,1,2")
    if nil != err {
    fmt.Println(err.Error())
    } else {
    fmt.Println(detectResult)
    }
分享:

    相关文档

    相关产品

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

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

*必选

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

字符长度不能超过200

提交反馈 取消

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

智能客服提问云社区提问