华为云用户手册

  • 功能介绍 认证测试中心提供以下功能: 执行认证测试中心 等保安全 当订单成功支付后,华为安全专家团队将为您量身定制等保合规整改方案,指导您进行安全服务的选型和部署,对您的网络、主机、数据库、安全管理制度等进行整改,优选具有资质的权威等保测评机构,提供专业的测评认证测试中心。 等保套餐 等保2.0产品优惠套餐为您提供一站式的安全解决方案,帮助您快速、低成本完成安全整改,轻松满足等保合规要求。 检测认证测试中心 认证测试服务后,系统自动生成认证测试中心认证测试报告,您会收到邮件和短信通知信息。您可在收到通知信息后下载认证测试中心报告。
  • 如何高效备份,容灾 传统场景采用文件或者块存储的数据库系统,备份恢复与数据量强相关,故在大数据量场景下,无法快速备份恢复,进而影响数据库的数据可靠性。 云数据库 GeminiDB基于DFV存储,底层采取Append Only方式存储,并在该基础上结合数据库逻辑进行分布式并行算法优化,极大地提升了数据备份、恢复性能。 DFV(Data Function Virtualization)是一个与数据库垂直整合的高性能,高可靠的分布式存储系统。存储集群采取池化部署,可以有效提升存储使用效率。 强大的数据快照处理能力,数据按多时间点多副本Append Only存储,快照秒级生成,支持海量快照。 并行高速备份、恢复备份及恢复逻辑下沉到各存储节点,本地访问数据并直接与存储系统交互,提高性能并发。 快速实例恢复 通过异步数据拷贝和按需实时数据加载机制,云数据库 GeminiDB实例可在数分钟内达到完整功能可用。 父主题: 关键特性
  • 架构概述 云数据库 GeminiDB是一款基于计算存储分离架构的分布式多模NoSQL数据库服务。在华为云高性能、高可用、高可靠、高安全、可弹性伸缩的基础上,提供了一键部署、备份恢复、监控报警等服务能力。目前包含GeminiDB Cassandra、GeminiDB Mongo、GeminiDB Influx和GeminiDB Redis四款产品,具有高读写性能,高性价比等优势,适用于IoT、互联网、游戏等领域。 云数据库 GeminiDB架构特点: 计算和存储资源解耦,独立弹性伸缩 计算节点全负荷分担 存储层内置多副本强一致 分布式共享存储接口,扩缩容无数据迁移 存储层提供超低时延数据访问 支持快速弹性扩缩容 快照备份恢复,效率高 多副本强一致性( AZ内/跨AZ ) 支持海量存储水平扩展及池化共享 支持超低时延访问(100us)
  • 如何在线弹性扩容,支持业务扩展 云数据库 GeminiDB云原生的计算存储分离架构,使得计算节点无状态,非常有利于业务扩展。 业务扩展面临计算节点、存储空间的两方面的扩容。 云数据库 GeminiDB共享存储,存储按需计费,一键扩容,不中断业务,最大支持96TB存储容量。 计算节点提供快速的双向扩展: 由于计算节点无状态,添加分片只需添加计算节点,无需额外购买存储,无需重建,无论多大数据量,都可以控制在5分钟左右。 云数据库 GeminiDB采用容器化部署,规格变更只涉及计算资源,只需修改容器参数即可,无需挂盘等操作,规格变更速度极快。 父主题: 关键特性
  • 如何保障数据库高可用 云数据库 GeminiDB采用计算存储分离架构,集群下多个数据库实例访问下层共享分布式存储,整体的故障有计算节点故障、存储节点故障两类。 图1 原理图 当计算节点故障,由于下层共享存储,其余非故障节点不需要进行数据恢复,直接接管业务,可提供秒级的故障切换,加上上层Proxy层链接保持能力,客户应用基本不感知故障发生。 而底层存储3副本,单点故障不会造成整体系统不可用。 图2 底层存储原理图 父主题: 关键特性
  • SDK列表 表1提供了云数据库 GeminiDB支持的SDK列表,您可以在代码仓库查看SDK更新历史、获取安装包以及查看指导文档。 表1 SDK列表 编程语言 Github地址 参考文档 Java huaweicloud-sdk-java-v3 Java SDK使用指导 Python huaweicloud-sdk-python-v3 Python SDK使用指导 Go huaweicloud-sdk-go-v3 Go SDK使用指导 .NET huaweicloud-sdk-net-v3 .NET SDK使用指导
  • 内容审核概述 内容审核(Content Moderation),是基于图像、文本、音频、视频、音频流、视频流、文档的检测技术,可自动检测涉黄、广告等内容,对用户上传的图片、文字进行内容审核,帮助客户降低业务违规风险。 内容审核以开放API(Application Programming Interface,应用程序编程接口)的方式提供给用户,用户通过实时访问和调用API获取推理结果,帮助用户自动采集关键数据,打造智能化业务系统,提升业务效率。
  • 添加数据示例 本章节对添加数据AK/SK方式使用SDK进行示例说明。 添加数据示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用AddDataParam类中的ImageUrl、Keywords、CustomNumTags、CustomTags、Desc、ItemId、Force配置服务输入参数,配置完成后运行即可。 添加数据调用示例代码如下: package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" imagesearch "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") iamEndpoint := "https://iam.cn-north-4.myhuaweicloud.com" endpoint := "https://mms.cn-north-4.myhuaweicloud.com" projectId := "project_id" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithIamEndpointOverride(iamEndpoint). WithProjectId(projectId). Build() // 初始化客户端 client := imagesearch.NewImageSearchClient( imagesearch.ImageSearchClientBuilder(). // 设置region, 示例中为北京四 WithRegion(region.NewRegion("cn-north-4", endpoint)). WithCredential(auth). Build()) request := &model.RunAddDataRequest{} request.ServiceName = "service_name" var listCustomNumTagsbody = map[string]float64{ "key": float64(1), } var listCustomTagsbody = map[string]string{ "key": "value", } // 替换为公网可以访问的图片地址 imageUrlAddDataParam:= "https://bucketname.obs.cn-north-4.myhuaweicloud.com/image/test1.jpg" request.Body = &model.AddDataParam{ ImageUrl: &imageUrlAddDataParam, CustomNumTags: listCustomNumTagsbody, CustomTags: listCustomTagsbody, ItemId: "item_id", } response, err := client.RunAddData(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 添加数据结果输出到控制台表示执行成功。 RunAddDataResponse { "result": "success", "data": { "image_info": { "objects": [ { "box": "135,489,1117,1341", "category": 1, "category_name": "top" } ] } } } 父主题: 使用SDK(GO)
  • 搜索数据示例 本章节对搜索数据AK/SK方式使用SDK进行示例说明。 搜索示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化SearchParam中的image_url、search_type、custom_tags、keywords、optional_params配置服务的输入参数,其中optionl_params为服务可选输入参数,配置完成后运行即可。 搜索数据调用示例代码如下: # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcore.region.region import Region as coreRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkimagesearch.v2 import * if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") iamEndpoint = "https://iam.cn-north-4.myhuaweicloud.com" endpoint = "https://mms.cn-north-4.myhuaweicloud.com" projectId = "project_id" credentials = BasicCredentials(ak, sk, projectId) \ .with_iam_endpoint(iamEndpoint) # 初始化客户端 client = ImageSearchClient.new_builder() \ .with_credentials(credentials) \ # 设置region, 示例中为北京四 .with_region(coreRegion(id="cn-north-4", endpoint=endpoint)) \ .build() try: request = RunSearchRequest() request.service_name = "service_name" optionalParamsbody = SearchOptionalParam( do_det=True, box="135,489,1117,1341", do_cls=True ) listCustomTagsCustomTags = [ "value1", "value2", "value3" ] listCustomTagsbody = { "key": listCustomTagsCustomTags } request.body = SearchParam( optional_params=optionalParamsbody, # 替换为公网可以访问的图片地址 image_url="https://bucketname.obs.cn-north-4.myhuaweicloud.com/image/test1.jpg ", custom_tags=listCustomTagsbody, offset=0, limit=30, search_type="CATEGORY" ) response = client.run_search(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 执行示例代码文件,控制台输出搜索数据结果即表示程序执行成功。 { "result": "success", "data": { "items": [ { "id": "item_id", "score": 1.0, "source": { "custom_tags": { "key": "value" } } } ], "search_info": { "total_num": 1, "return_num": 1, "search_time": 969 }, "image_info": { "box": "135,489,1117,1341", "category": 0, "category_name": "others", "objects": [ { "box": "135,489,1117,1341", "category": 0, "category_name": "others" } ] } } } 父主题: 使用SDK(Python)
  • 添加数据示例 本章节对添加数据AK/SK方式使用SDK进行示例说明。 添加数据示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化AddDataParam类中的image_url、custom_num_tags、custom_tags、desc、item_id、force配置服务输入参数,配置完成后运行即可。 添加数据调用示例代码如下: # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcore.region.region import Region as coreRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkimagesearch.v2 import * if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") iamEndpoint = "https://iam.cn-north-4.myhuaweicloud.com" endpoint = "https://mms.cn-north-4.myhuaweicloud.com" projectId = "project_id" credentials = BasicCredentials(ak, sk, projectId) \ .with_iam_endpoint(iamEndpoint) # 初始化客户端 client = ImageSearchClient.new_builder() \ .with_credentials(credentials) \ # 设置region, 示例中为北京四 .with_region(coreRegion(id="cn-north-4", endpoint=endpoint)) \ .build() try: request = RunAddDataRequest() request.service_name = "service_name" listCustomNumTagsbody = { "key": 1 } listCustomTagsbody = { "key": "value" } request.body = AddDataParam( # 替换为公网可以访问的图片地址 image_url="https://bucketname.obs.cn-north-4.myhuaweicloud.com/image/test1.jpg", custom_num_tags=listCustomNumTagsbody, custom_tags=listCustomTagsbody, item_id="item_id" ) response = client.run_add_data(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 执行示例代码,控制台输出添加数据结果即表示程序执行成功。 { "result": "success", "data": { "image_info": { "objects": [ { "box": "135,489,1117,1341", "category": 1, "category_name": "top" } ] } } } 父主题: 使用SDK(Python)
  • 检查数据示例 本章节对检查数据AK/SK方式使用SDK进行示例说明。 检查数据示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用CheckParam中的ItemId参数配置数据的服务实例级唯一标识,配置完成后运行即可。 检查数据调用示例代码如下: package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" imagesearch "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") iamEndpoint := "https://iam.cn-north-4.myhuaweicloud.com" endpoint := "https://mms.cn-north-4.myhuaweicloud.com" projectId := "project_id" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithIamEndpointOverride(iamEndpoint). WithProjectId(projectId). Build() // 初始化客户端 client := imagesearch.NewImageSearchClient( imagesearch.ImageSearchClientBuilder(). // 设置region, 示例中为北京四 WithRegion(region.NewRegion("cn-north-4", endpoint)). WithCredential(auth). Build()) request := &model.RunCheckDataRequest{} request.ServiceName = "service_name" itemIdCheckParam:= "item_id" request.Body = &model.CheckParam{ ItemId: &itemIdCheckParam, } response, err := client.RunCheckData(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 执行示例代码文件,控制台输出检查数据结果即表示程序执行成功。 RunCheckDataResponse { "result": "success", "data": { "existed": true, "item_info": { "custom_tags": { "key": "value" }, "custom_num_tags": { "key":value } } } } 父主题: 使用SDK(GO)
  • 检查数据示例 本章节对检查数据AK/SK方式使用SDK进行示例说明。 检查数据示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用CheckParam类的setItemId设置数据的服务实例级唯一标识,配置完成后运行即可。 检查数据调用示例代码如下: package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.core.region.Region; import com.huaweicloud.sdk.imagesearch.v2.*; import com.huaweicloud.sdk.imagesearch.v2.model.*; /** * 检查数据 */ public class RunCheckDataSolution { public static void main(String[] args) { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK String ak = System.getenv("HUAWEICLOUD_SDK_AK"); String sk = System.getenv("HUAWEICLOUD_SDK_SK"); String iamEndpoint = "https://iam.cn-north-4.myhuaweicloud.com"; String endpoint = "https://mms.cn-north-4.myhuaweicloud.com"; String projectId = "project_id"; // 初始化客户端 ICredential auth = new BasicCredentials() .withIamEndpoint(iamEndpoint) .withProjectId(projectId) .withAk(ak) .withSk(sk); ImageSearchClient client = ImageSearchClient.newBuilder() .withCredential(auth) // 设置region, 示例中为北京四 .withRegion(new Region("cn-north-4", endpoint)) .build(); RunCheckDataRequest request = new RunCheckDataRequest(); request.withServiceName("service_name"); CheckParam body = new CheckParam(); body.withItemId("item_id"); request.withBody(body); try { RunCheckDataResponse response = client.runCheckData(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } 执行示例代码文件,控制台输出检查数据结果即表示程序执行成功。 class RunCheckDataResponse { result: success data: class CheckRestInfo { existed: true itemInfo: class ItemSource { desc: null customTags: {key=value} customNumTags: {key=1.0} keywords: null } items: null checkInfo: null } } 父主题: 使用SDK(Java)
  • 搜索数据示例 本章节对搜索数据AK/SK方式使用SDK进行示例说明。 搜索示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用SearchParam类的ImageUrl、SearchType、OptionalParams、Keywords、CustomTags配置服务输入参数,其中OptionalParams为服务可选输入参数,配置完成后运行即可。 搜索数据调用示例代码如下: package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" imagesearch "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") iamEndpoint := "https://iam.cn-north-4.myhuaweicloud.com" endpoint := "https://mms.cn-north-4.myhuaweicloud.com" projectId := "project_id" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithIamEndpointOverride(iamEndpoint). WithProjectId(projectId). Build() // 初始化客户端 client := imagesearch.NewImageSearchClient( imagesearch.ImageSearchClientBuilder(). // 设置region, 示例中为北京四 WithRegion(region.NewRegion("cn-north-4", endpoint)). WithCredential(auth). Build()) request := &model.RunSearchRequest{} request.ServiceName = "service_name" doDetOptionalParams:= true boxOptionalParams:= "135,489,1117,1341" doClsOptionalParams:= true optionalParamsbody := &model.SearchOptionalParam{ DoDet: &doDetOptionalParams, Box: &boxOptionalParams, DoCls: &doClsOptionalParams, } var listCustomTagsCustomTags = []string{ "value1", "value2", "value3", } var listCustomTagsbody = map[string][]string{ "key": listCustomTagsCustomTags, } // 替换为公网可以访问的图片地址 imageUrlSearchParam:= "https://bucketname.obs.cn-north-4.myhuaweicloud.com/image/test1.jpg " offsetSearchParam:= int32(0) limitSearchParam:= int32(30) request.Body = &model.SearchParam{ OptionalParams: optionalParamsbody, ImageUrl: &imageUrlSearchParam, CustomTags: listCustomTagsbody, Offset: &offsetSearchParam, Limit: &limitSearchParam, SearchType: model.GetSearchParamSearchTypeEnum().CATEGORY, } response, err := client.RunSearch(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 执行示例代码文件,控制台输出搜索数据结果即表示程序执行成功。 RunSearchResponse { "result": "success", "data": { "items": [ { "id": "item_id", "score": 1.0, "source": { "custom_tags": { "key": "value" } } } ], "search_info": { "total_num": 1, "return_num": 1, "search_time": 969 }, "image_info": { "box": "135,489,1117,1341", "category": 0, "category_name": "others", "objects": [ { "box": "135,489,1117,1341", "category": 0, "category_name": "others" } ] } } } 父主题: 使用SDK(GO)
  • 更新数据示例 本章节对更新数据AK/SK方式使用SDK进行示例说明。 更新数据示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化UpdateParam中的custom_num_tags、custom_tags、desc、item_id配置服务输入参数,配置完成后运行即可。 更新数据调用示例代码如下: # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcore.region.region import Region as coreRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkimagesearch.v2 import * if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") iamEndpoint = "https://iam.cn-north-4.myhuaweicloud.com" endpoint = "https://mms.cn-north-4.myhuaweicloud.com" projectId = "project_id" credentials = BasicCredentials(ak, sk, projectId) \ .with_iam_endpoint(iamEndpoint) # 初始化客户端 client = ImageSearchClient.new_builder() \ .with_credentials(credentials) \ # 设置region, 示例中为北京四 .with_region(coreRegion(id="cn-north-4", endpoint=endpoint)) \ .build() try: request = RunUpdateDataRequest() request.service_name = "service_name" listCustomNumTagsbody = { "key": 1 } listCustomTagsbody = { "key": "value" } request.body = UpdateParam( custom_num_tags=listCustomNumTagsbody, custom_tags=listCustomTagsbody, desc="description", item_id="item_id" ) response = client.run_update_data(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 执行示例代码文件,控制台输出更新数据结果即表示程序执行成功。 { "result": "success" } 父主题: 使用SDK(Python)
  • 删除数据示例 本章节对删除数据AK/SK方式使用SDK进行示例说明。 删除数据示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化DeleteParam中的ItemId参数配置数据的服务实例级唯一标识,配置完成后运行即可。 删除数据调用示例代码如下: using System; using System.Collections.Generic; using HuaweiCloud.SDK.Core; using HuaweiCloud.SDK.Core.Auth; using HuaweiCloud.SDK.ImageSearch; using HuaweiCloud.SDK.ImageSearch.V2; using HuaweiCloud.SDK.ImageSearch.V2.Model; namespace RunDeleteDataSolution { class Program { static void Main(string[] args) { //认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 //本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK string accessKey= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_AK", EnvironmentVariableTarget.Machine); string secretKey= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_SK", EnvironmentVariableTarget.Machine); const string iamEndpoint = "https://iam.cn-north-4.myhuaweicloud.com"; const string endpoint = "https://mms.cn-north-4.myhuaweicloud.com"; const string projectId = "project_id"; var config = HttpConfig.GetDefaultConfig(); config.IgnoreSslVerification = true; var auth = new BasicCredentials(ak, sk, projectId).WithIamEndpoint(iamEndpoint); // 初始化客户端 var client = ImageSearchClient.NewBuilder() .WithCredential(auth) // 设置region, 示例中为北京四 .WithRegion(new Region("cn-north-4", endpoint)) .WithHttpConfig(config) .Build(); var req = new RunDeleteDataRequest { ServiceName = "service_name" }; req.Body = new DeleteParam() { ItemId = "item_id" }; try { var resp = client.RunDeleteData(req); var respStatusCode = resp.HttpStatusCode; Console.WriteLine(respStatusCode); } catch (RequestTimeoutException requestTimeoutException) { Console.WriteLine(requestTimeoutException.ErrorMessage); } catch (ServiceResponseException clientRequestException) { Console.WriteLine(clientRequestException.HttpStatusCode); Console.WriteLine(clientRequestException.RequestId); Console.WriteLine(clientRequestException.ErrorCode); Console.WriteLine(clientRequestException.ErrorMsg); } catch (ConnectionException connectionException) { Console.WriteLine(connectionException.ErrorMessage); } } } } 执行示例代码文件,控制台输出删除数据结果即表示程序执行成功。 200 { "result": "success" } 父主题: 使用SDK(.NET)
  • 删除数据示例 本章节对删除数据AK/SK方式使用SDK进行示例说明。 删除数据示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化DeleteParam中的item_id参数配置数据的服务实例级唯一标识,配置完成后运行即可。 删除数据调用示例代码如下: # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcore.region.region import Region as coreRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkimagesearch.v2 import * if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") iamEndpoint = "https://iam.cn-north-4.myhuaweicloud.com" endpoint = "https://mms.cn-north-4.myhuaweicloud.com" projectId = "project_id" credentials = BasicCredentials(ak, sk, projectId) \ .with_iam_endpoint(iamEndpoint) # 初始化客户端 client = ImageSearchClient.new_builder() \ .with_credentials(credentials) \ # 设置region, 示例中为北京四 .with_region(coreRegion(id="cn-north-4", endpoint=endpoint)) \ .build() try: request = RunDeleteDataRequest() request.service_name = "service_name" request.body = DeleteParam( item_id="item_id" ) response = client.run_delete_data(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 执行示例代码文件,控制台输出删除数据结果即表示程序执行成功。 { "result": "success" } 父主题: 使用SDK(Python)
  • 删除数据示例 本章节对删除数据AK/SK方式使用SDK进行示例说明。 删除数据示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化DeleteParam中的ItemId参数配置数据的服务实例级唯一标识,配置完成后运行即可。 删除数据调用示例代码如下: package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" imagesearch "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") iamEndpoint := "https://iam.cn-north-4.myhuaweicloud.com" endpoint := "https://mms.cn-north-4.myhuaweicloud.com" projectId := "project_id" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithIamEndpointOverride(iamEndpoint). WithProjectId(projectId). Build() // 初始化客户端 client := imagesearch.NewImageSearchClient( imagesearch.ImageSearchClientBuilder(). // 设置region, 示例中为北京四 WithRegion(region.NewRegion("cn-north-4", endpoint)). WithCredential(auth). Build()) request := &model.RunDeleteDataRequest{} request.ServiceName = "service_name" itemIdDeleteParam:= "item_id" request.Body = &model.DeleteParam{ ItemId: &itemIdDeleteParam, } response, err := client.RunDeleteData(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 执行示例代码文件,控制台输出删除数据结果即表示程序执行成功。 RunDeleteDataResponse { "result": "success" } 父主题: 使用SDK(GO)
  • 检查数据示例 本章节对检查数据AK/SK方式使用SDK进行示例说明。 检查数据示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用CheckParam中的ItemId参数配置数据的服务实例级唯一标识,配置完成后运行即可。 更新数据调用示例代码如下: using System; using System.Collections.Generic; using HuaweiCloud.SDK.Core; using HuaweiCloud.SDK.Core.Auth; using HuaweiCloud.SDK.ImageSearch; using HuaweiCloud.SDK.ImageSearch.V2; using HuaweiCloud.SDK.ImageSearch.V2.Model; namespace RunCheckDataSolution { class Program { static void Main(string[] args) { //认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 //本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK string accessKey= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_AK", EnvironmentVariableTarget.Machine); string secretKey= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_SK", EnvironmentVariableTarget.Machine); const string iamEndpoint = "https://iam.cn-north-4.myhuaweicloud.com"; const string endpoint = "https://mms.cn-north-4.myhuaweicloud.com"; const string projectId = "project_id"; var config = HttpConfig.GetDefaultConfig(); config.IgnoreSslVerification = true; var auth = new BasicCredentials(ak, sk, projectId).WithIamEndpoint(iamEndpoint); // 初始化客户端 var client = ImageSearchClient.NewBuilder() .WithCredential(auth) // 设置region, 示例中为北京四 .WithRegion(new Region("cn-north-4", endpoint)) .WithHttpConfig(config) .Build(); var req = new RunCheckDataRequest { ServiceName = "service_name" }; req.Body = new CheckParam() { ItemId = "item_id" }; try { var resp = client.RunCheckData(req); var respStatusCode = resp.HttpStatusCode; Console.WriteLine(respStatusCode); } catch (RequestTimeoutException requestTimeoutException) { Console.WriteLine(requestTimeoutException.ErrorMessage); } catch (ServiceResponseException clientRequestException) { Console.WriteLine(clientRequestException.HttpStatusCode); Console.WriteLine(clientRequestException.RequestId); Console.WriteLine(clientRequestException.ErrorCode); Console.WriteLine(clientRequestException.ErrorMsg); } catch (ConnectionException connectionException) { Console.WriteLine(connectionException.ErrorMessage); } } } } 执行示例代码文件,控制台输出检查数据结果即表示程序执行成功。 200 { "result": "success", "data": { "existed": true, "item_info": { "custom_tags": { "key": "value" }, "custom_num_tags": { "key": value } } } } 父主题: 使用SDK(.NET)
  • 检查数据示例 本章节对检查数据AK/SK方式使用SDK进行示例说明。 检查数据示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化CheckParam中的item_id参数配置数据的服务实例级唯一标识,配置完成后运行即可。 搜过图片调用示例代码如下: # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcore.region.region import Region as coreRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkimagesearch.v2 import * if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") iamEndpoint = "https://iam.cn-north-4.myhuaweicloud.com" endpoint = "https://mms.cn-north-4.myhuaweicloud.com" projectId = "project_id" credentials = BasicCredentials(ak, sk, projectId) \ .with_iam_endpoint(iamEndpoint) # 初始化客户端 client = ImageSearchClient.new_builder() \ .with_credentials(credentials) \ # 设置region, 示例中为北京四 .with_region(coreRegion(id="cn-north-4", endpoint=endpoint)) \ .build() try: request = RunCheckDataRequest() request.service_name = "service_name" request.body = CheckParam( item_id="item_id" ) response = client.run_check_data(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 执行示例代码文件,控制台输出检查数据结果即表示程序执行成功。 { "result": "success", "data": { "existed": true, "item_info": { "custom_tags": { "key": "value" }, "custom_num_tags": { "key":"value" } } } } 父主题: 使用SDK(Python)
  • 更新数据示例 本章节对更新数据AK/SK方式使用SDK进行示例说明。 更新数据示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化UpdateParam中的CustomNumTags、CustomTags、Desc、ItemId配置服务输入参数,配置完成后运行即可。 更新数据调用示例代码如下: package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" imagesearch "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") iamEndpoint := "https://iam.cn-north-4.myhuaweicloud.com" endpoint := "https://mms.cn-north-4.myhuaweicloud.com" projectId := "project_id" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithIamEndpointOverride(iamEndpoint). WithProjectId(projectId). Build() // 初始化客户端 client := imagesearch.NewImageSearchClient( imagesearch.ImageSearchClientBuilder(). // 设置region, 示例中为北京四 WithRegion(region.NewRegion("cn-north-4", endpoint)). WithCredential(auth). Build()) request := &model.RunUpdateDataRequest{} request.ServiceName = "service_name" var listCustomNumTagsbody = map[string]float64{ "key": float64(1), } var listCustomTagsbody = map[string]string{ "key": "value", } descUpdateParam:= "description" request.Body = &model.UpdateParam{ CustomNumTags: listCustomNumTagsbody, CustomTags: listCustomTagsbody, Desc: &descUpdateParam, ItemId: "item_id", } response, err := client.RunUpdateData(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 执行示例代码文件,控制台输出更新数据结果即表示程序执行成功。添加图片结果输出到控制台。 RunUpdateDataResponse { "result": "success" } 父主题: 使用SDK(GO)
  • 主体识别示例 本章节对主体识别AK/SK方式使用SDK进行示例说明。 主体识别示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用ImageMainObjectDetectionReq中的withUrl或withImage方法配置图像信息(image和url参数二选一),示例中以url为例,配置完成后运行即可。 endpoint是华为云各服务应用区域和各服务的终端节点,详情请查看 地区和终端节点 。 主体识别调用示例代码如下: package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.image.v2.region.ImageRegion; import com.huaweicloud.sdk.image.v2.*; import com.huaweicloud.sdk.image.v2.model.*; public class RunImageMainObjectDetectionSolution { public static void main(String[] args) { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK String ak = System.getenv("HUAWEICLOUD_SDK_AK"); String sk = System.getenv("HUAWEICLOUD_SDK_SK"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); ImageClient client = ImageClient.newBuilder() .withCredential(auth) .withRegion(ImageRegion.valueOf("cn-north-4")) //此处替换为您开通服务的区域 .build(); RunImageMainObjectDetectionRequest request = new RunImageMainObjectDetectionRequest(); ImageMainObjectDetectionReq body = new ImageMainObjectDetectionReq(); body.withThreshold(30f); body.withUrl("https://XXX.jpg"); //替换为公网可以访问的图片地址 request.withBody(body); try { RunImageMainObjectDetectionResponse response = client.runImageMainObjectDetection(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } 执行示例代码文件,控制台输出主体识别结果即表示程序执行成功。相关参数说明请参考主体识别API。 RunImageMainObjectDetectionResponse { result: [class ImageMainObjectDetectionInstance { label: bounding_box location: {height=327.77, top_left_x=3.7, top_left_y=1.72, width=463.03} confidence: 95.73 }, class ImageMainObjectDetectionInstance { label: main_object_box location: {height=328.35, top_left_x=3.22, top_left_y=1.5, width=456.63} confidence: 88.35 }] } 父主题: 使用SDK(Java)
  • 名人识别示例 本章节对名人识别AK/SK方式使用SDK进行示例说明。 名人识别示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用CelebrityRecognitionReq中的withUrl或withImage方法配置图像信息(image和url参数二选一),示例中以url为例,配置完成后运行即可。 endpoint是华为云各服务应用区域和各服务的终端节点,详情请查看 地区和终端节点 。 名人识别调用示例代码如下: package com.huaweicloud.sdk.test; import com.alibaba.fastjson.JSON; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.image.v2.ImageClient; import com.huaweicloud.sdk.image.v2.model.RunCelebrityRecognitionRequest; import com.huaweicloud.sdk.image.v2.region.ImageRegion; import com.huaweicloud.sdk.image.v2.model.CelebrityRecognitionReq; import com.huaweicloud.sdk.image.v2.model.RunCelebrityRecognitionResponse; public class RunCelebrityRecognitionSolution { public static void main(String[] args) { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK String ak = System.getenv("HUAWEICLOUD_SDK_AK"); String sk = System.getenv("HUAWEICLOUD_SDK_SK"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); ImageClient client = ImageClient.newBuilder() .withCredential(auth) .withRegion(ImageRegion.valueOf("cn-north-1")) //此处替换为您开通服务的区域 .build(); RunCelebrityRecognitionRequest request = new RunCelebrityRecognitionRequest(); CelebrityRecognitionReq body = new CelebrityRecognitionReq(); body.withThreshold(0f); body.withUrl("https://XXX.jpg"); //此处替换为公网可以访问的图片地址 request.withBody(body); try { RunCelebrityRecognitionResponse response = client.runCelebrityRecognition(request); System.out.println(response.getHttpStatusCode()); System.out.println(JSON.toJSONString(response)); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } 执行示例代码文件,控制台输出名人识别结果即表示程序执行成功。相关参数说明请参考名人识别API。 200 {"httpStatusCode":200,"result":[{"confidence":0.9990679,"faceDetail":{"w":357,"h":510,"x":260,"y":201},"label":"迈克尔·杰克逊"}]} Process finished with exit code 0 父主题: 使用SDK(Java)
  • 翻拍识别示例 本章节对翻拍识别AK/SK方式使用SDK进行示例说明。 翻拍识别示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化RunRecaptureDetectReq中的Image或Url配置图像信息(image和url参数二选一),示例中以url为例,配置完成后运行即可。 endpoint是华为云各服务应用区域和各服务的终端节点,详情请查看 地区和终端节点 。 翻拍识别调用示例代码如下: package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" image "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/image/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/image/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/image/v2/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := image.NewImageClient( image.ImageClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). //此处替换为您开通服务的区域 WithCredential(auth). Build()) request := &model.RunRecaptureDetectRequest{} thresholdRecaptureDetectReq:= float32(0) urlRecaptureDetectReq:= "https://bucketname.obs.cn-north-4.myhuaweicloud.com/image/test1.jpg"//替换为公网可以访问的图片地址 request.Body = &model.RecaptureDetectReq{ Threshold: &thresholdRecaptureDetectReq, Url: &urlRecaptureDetectReq, } response, err := client.RunRecaptureDetect(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 识别结果输出到控制台表示执行成功。 {"result":{"suggestion":"false","category":"recapture","score":"0.9998","detail":[{"label":"recapture","confidence":"0.9998"}]}} 父主题: 使用SDK(GO)
  • 主体识别示例 本章节对主体识别AK/SK方式使用SDK进行示例说明。 主体识别示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化ImageMainObjectDetectionReq中的Image或Url配置图像信息(image和url参数二选一),示例中以url为例,配置完成后运行即可。 endpoint是华为云各服务应用区域和各服务的终端节点,详情请查看 地区和终端节点 。 主体识别调用示例代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" image "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/image/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/image/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/image/v2/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := image.NewImageClient( image.ImageClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). //此处替换为您开通服务的区域 WithCredential(auth). Build()) request := &model.RunImageMainObjectDetectionRequest{} thresholdImageMainObjectDetectionReq:= float32(30) urlImageMainObjectDetectionReq:= "https://XXX.jpg" //此处替换为公网可以访问的图片地址 request.Body = &model.ImageMainObjectDetectionReq{ Threshold: &thresholdImageMainObjectDetectionReq, Url: &urlImageMainObjectDetectionReq, } response, err := client.RunImageMainObjectDetection(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } 识别结果输出到控制台表示执行成功。相关参数说明请参考主体识别API。 1 RunImageMainObjectDetectionResponse {"result":[{"label":"bounding_box","location":{"height":327.77,"top_left_x":3.7,"top_left_y":1.72,"width":463.03},"confidence":"95.73"},{"label":"main_object_box","location":{"height":328.35,"top_left_x":3.22,"top_left_y":1.5,"width":456.63},"confidence":"88.35"}]} 父主题: 使用SDK(GO)
  • 图像标签示例 本章节对图像标签AK/SK方式使用SDK进行示例说明。 图像标签示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化ImageTaggingReq中的url或image配置图像信息(image和url参数二选一),示例中以url为例,配置完成后运行即可。 endpoint是华为云各服务应用区域和各服务的终端节点,详情请查看 地区和终端节点 。 图像标签调用示例代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcore.http.http_config import HttpConfig from huaweicloudsdkimage.v2 import ImageClient,RunImageTaggingRequest,ImageTaggingReq from huaweicloudsdkimage.v2.region.image_region import ImageRegion if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) client = ImageClient.new_builder() \ .with_credentials(credentials) \ .with_region(ImageRegion.value_of("cn-north-1")) \ //此处替换为您开通服务的区域 .build() try: request = RunImageTaggingRequest() request.body = ImageTaggingReq( limit=50, threshold=95, language="zh", url="https://XXX.jpg" //此处替换为公网可以访问的图片地址 ) response = client.run_image_tagging(request) print(response.status_code) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 执行示例代码,控制台返回200即表示程序执行成功。相关参数说明请参考图像标签API。 1 2 3 200 {"result": {"tags": [{"confidence": "98.00", "type": "树", "tag": "树", "i18n_tag": {"zh": "树", "en": "Tree"}, "i18n_type": {"zh": "树", "en": "Tree"}, "instances": []}]}} Process finished with exit code 0 父主题: 使用SDK(Python)
  • 图像标签示例 本章节对图像标签AK/SK方式使用SDK进行示例说明。 图像标签示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化ImageTaggingReq中的Image或Url配置图像信息(image和url参数二选一),示例中以url为例,配置完成后运行即可。 endpoint是华为云各服务应用区域和各服务的终端节点,详情请查看 地区和终端节点 。 图像标签调用示例代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" image "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/image/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/image/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/image/v2/region" ) func main() { // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak := os.Getenv("HUAWEICLOUD_SDK_AK") sk := os.Getenv("HUAWEICLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := image.NewImageClient( image.ImageClientBuilder(). WithRegion(region.ValueOf("cn-north-1")). //此处替换为您开通服务的区域 WithCredential(auth). Build()) request := &model.RunImageTaggingRequest{} limitImageTaggingReq:= int32(50) thresholdImageTaggingReq:= float32(95) languageImageTaggingReq:= "zh" urlImageTaggingReq:= "https://XXX.jpg" //此处替换为公网可以访问的图片地址 request.Body = &model.ImageTaggingReq{ Limit: &limitImageTaggingReq, Threshold: &thresholdImageTaggingReq, Language: &languageImageTaggingReq, Url: &urlImageTaggingReq, } response, err := client.RunImageTagging(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) }} 识别结果输出到控制台表示执行成功。相关参数说明请参考图像标签API。 1 2 RunImageTaggingResponse {"result": {"tags": [{"confidence": "98.01", "type": "树", "tag": "树", "i18n_tag": {"zh": "树", "en": "Tree"}, "i18n_type": {"zh": "树", "en": "Tree"}, "instances": []}]}} Process exiting with code: 0 父主题: 使用SDK(GO)
  • 翻拍识别示例 本章节对翻拍识别AK/SK方式使用SDK进行示例说明。 翻拍识别示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化RunRecaptureDetectReq中的url或image配置图像信息(image和url参数二选一),示例中以url为例,配置完成后运行即可。 endpoint是华为云各服务应用区域和各服务的终端节点,详情请查看 地区和终端节点 。 翻拍识别调用示例代码如下: # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkimage.v2.region.image_region import ImageRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkimage.v2 import * if __name__ == "__main__": # 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.getenv("HUAWEICLOUD_SDK_AK") sk = os.getenv("HUAWEICLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = ImageClient.new_builder() \ .with_credentials(credentials) \ .with_region(ImageRegion.value_of("cn-north-4")) \ //此处替换为您开通服务的区域 .build() try: request = RunRecaptureDetectRequest() request.body = RecaptureDetectReq( threshold=0, url="https://bucketname.obs.cn-north-4.myhuaweicloud.com/image/test1.jpg"//替换为公网可以访问的图片地址 ) response = client.run_recapture_detect(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) 执行示例代码文件,控制台输出翻拍识别结果即表示程序执行成功。 {"result":{"suggestion":"false","category":"recapture","score":"0.9998","detail":[{"label":"recapture","confidence":"0.9998"}]}} 父主题: 使用SDK(Python)
  • 名人识别示例 本章节对名人识别AK/SK方式使用SDK进行示例说明。 名人识别示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用CelebrityRecognitionReq中的url或image方法配置图像信息(image和url参数二选一),示例中以url为例,配置完成后运行即可。 endpoint是华为云各服务应用区域和各服务的终端节点,详情请查看 地区和终端节点 。 名人识别调用示例代码如下: using System; using System.Collections.Generic; using HuaweiCloud.SDK.Core; using HuaweiCloud.SDK.Core.Auth; using HuaweiCloud.SDK.Image; using HuaweiCloud.SDK.Image.V2; using HuaweiCloud.SDK.Image.V2.Model; using Newtonsoft.Json; namespace RunCelebrityRecognitionSolution { class Program { static void Main(string[] args){ //认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 //本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK string accessKey= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_AK", EnvironmentVariableTarget.Machine); string secretKey= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_SK", EnvironmentVariableTarget.Machine); var config = HttpConfig.GetDefaultConfig(); config.IgnoreSslVerification = true; var auth = new BasicCredentials(ak, sk); var client = ImageClient.NewBuilder() .WithCredential(auth) .WithRegion(ImageRegion.ValueOf("cn-north-1")) //此处替换为您开通服务的区域 .WithHttpConfig(config) .Build(); var req = new RunCelebrityRecognitionRequest { }; req.Body = new CelebrityRecognitionReq() { Threshold = 0.48, Url = "https://XXX.jpg" //此处替换为公网可以访问的图片地址 }; try { var resp = client.RunCelebrityRecognition(req); var respStatusCode = resp.HttpStatusCode; Console.WriteLine(respStatusCode); Console.WriteLine(JsonConvert.DeserializeObject(resp.HttpBody)); } catch (RequestTimeoutException requestTimeoutException) { Console.WriteLine(requestTimeoutException.ErrorMessage); } catch (ServiceResponseException clientRequestException) { Console.WriteLine(clientRequestException.HttpStatusCode); Console.WriteLine(clientRequestException.ErrorCode); Console.WriteLine(clientRequestException.ErrorMsg); } catch (ConnectionException connectionException) { Console.WriteLine(connectionException.ErrorMessage); } } } } 执行示例代码文件,控制台输出名人识别结果即表示程序执行成功。相关参数说明请参考名人识别API。 1 2 3 4 5 6 7 8 9 10 11 12 13 200 { 'result': [{ 'confidence': 0.9990678852332598, 'face_detail': { 'h': 510, 'w': 357, 'x': 260, 'y': 201 }, 'label': '迈克尔·杰克逊' }] } 父主题: 使用SDK(.NET)
  • 翻拍识别示例 本章节对翻拍识别AK/SK方式使用SDK进行示例说明。 翻拍识别示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用RunRecaptureDetectReq中的url或image方法配置图像信息(image和url参数二选一),示例中以url为例,配置完成后运行即可。 endpoint是华为云各服务应用区域和各服务的终端节点,详情请查看 地区和终端节点 。 翻拍识别调用示例代码如下: using System; using System.Collections.Generic; using HuaweiCloud.SDK.Core; using HuaweiCloud.SDK.Core.Auth; using HuaweiCloud.SDK.Image; using HuaweiCloud.SDK.Image.V2; using HuaweiCloud.SDK.Image.V2.Model; namespace RunRecaptureDetectSolution { class Program { static void Main(string[] args) { //认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 //本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK string accessKey= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_AK", EnvironmentVariableTarget.Machine); string secretKey= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_SK", EnvironmentVariableTarget.Machine); var config = HttpConfig.GetDefaultConfig(); config.IgnoreSslVerification = true; var auth = new BasicCredentials(ak, sk); var client = ImageClient.NewBuilder() .WithCredential(auth) .WithRegion(ImageRegion.ValueOf("cn-north-4")) //此处替换为您开通服务的区域 .WithHttpConfig(config) .Build(); var req = new RunRecaptureDetectRequest { }; req.Body = new RecaptureDetectReq() { Threshold = 0, Url = "https://bucketname.obs.cn-north-4.myhuaweicloud.com/image/test1.jpg"//替换为公网可以访问的图片地址 }; try { var resp = client.RunRecaptureDetect(req); var respStatusCode = resp.HttpStatusCode; Console.WriteLine(respStatusCode); Console.WriteLine(resp.HttpBody); } catch (RequestTimeoutException requestTimeoutException) { Console.WriteLine(requestTimeoutException.ErrorMessage); } catch (ServiceResponseException clientRequestException) { Console.WriteLine(clientRequestException.HttpStatusCode); Console.WriteLine(clientRequestException.RequestId); Console.WriteLine(clientRequestException.ErrorCode); Console.WriteLine(clientRequestException.ErrorMsg); } catch (ConnectionException connectionException) { Console.WriteLine(connectionException.ErrorMessage); } } } } 执行示例代码文件,控制台输出翻拍识别结果即表示程序执行成功。 200 {"result":{"suggestion":"false","category":"recapture","score":"0.9998","detail":[{"label":"recapture","confidence":"0.9998"}]}} 父主题: 使用SDK(.NET)
  • 图像标签示例 本章节对图像标签AK/SK方式使用SDK进行示例说明。 图像标签示例代码只需将AK/SK信息替换为实际AK/SK,代码中可以使用初始化ImageTaggingReq中的url或image配置图像信息(image和url参数二选一),示例中以url为例,配置完成后运行即可。 endpoint是华为云各服务应用区域和各服务的终端节点,详情请查看 地区和终端节点 。 图像标签调用示例代码如下: using System; using System.Collections.Generic; using HuaweiCloud.SDK.Core; using HuaweiCloud.SDK.Core.Auth; using HuaweiCloud.SDK.Image; using HuaweiCloud.SDK.Image.V2; using HuaweiCloud.SDK.Image.V2.Model; using Newtonsoft.Json; namespace RunImageTaggingSolution { class Program { static void Main(string[] args) { //认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全 //本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK string accessKey= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_AK", EnvironmentVariableTarget.Machine); string secretKey= Environment.GetEnvironmentVariable("HUAWEICLOUD_SDK_SK", EnvironmentVariableTarget.Machine); var config = HttpConfig.GetDefaultConfig(); config.IgnoreSslVerification = true; var auth = new BasicCredentials(ak, sk); var client = ImageClient.NewBuilder() .WithCredential(auth) .WithRegion(ImageRegion.ValueOf("cn-north-1")) //此处替换为您开通服务的区域 .WithHttpConfig(config) .Build(); var req = new RunImageTaggingRequest { }; req.Body = new ImageTaggingReq() { Limit = 50, Threshold = 95, Language = "zh", Url = "https://XXX.jpg" //此处替换为公网可以访问的图片地址 }; try { var resp = client.RunImageTagging(req); var respStatusCode = resp.HttpStatusCode; Console.WriteLine(respStatusCode); Console.WriteLine(JsonConvert.DeserializeObject(resp.HttpBody)); } catch (RequestTimeoutException requestTimeoutException) { Console.WriteLine(requestTimeoutException.ErrorMessage); } catch (ServiceResponseException clientRequestException) { Console.WriteLine(clientRequestException.HttpStatusCode); Console.WriteLine(clientRequestException.ErrorCode); Console.WriteLine(clientRequestException.ErrorMsg); } catch (ConnectionException connectionException) { Console.WriteLine(connectionException.ErrorMessage); } } } } 执行示例代码,控制台返回200即表示程序执行成功。相关参数说明请参考图像标签API。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 200 { "result": { "tags": [ { "confidence": "98.01", "type": "树", "tag": "树", "i18n_tag": { "zh": "树", "en": "Tree" }, "i18n_type": { "zh": "树", "en": "Tree" }, "instances": [ ] } ] } } 父主题: 使用SDK(.NET)
共100000条