文档中心>数据万象

图片搜索接口

最近更新时间:2023-12-01 17:57:57

我的收藏

简介

本文档提供关于图片搜索接口的相关 API 概览以及 SDK 示例代码。
API
操作描述
该接口用于检索图片。

图片搜索接口

该接口用于检索图片。

方法原型

func (s *CIService) ImageSearch(ctx context.Context, name string, opt *ImageSearchOptions) (*ImageSearchResult, *Response, error)

请求示例

// 将 examplebucket-1250000000 和 COS_REGION 修改为真实的信息
// CI 任务需要提供 CIURL
bu, _ := url.Parse("https://examplebucket-1250000000.cos.COS_REGION.myqcloud.com")
cu, _ := url.Parse("https://examplebucket-1250000000.ci.COS_REGION.myqcloud.com")
b := &cos.BaseURL{BucketURL: bu, CIURL: cu}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: os.Getenv("SECRETID"),
SecretKey: os.Getenv("SECRETKEY"),
}
})
opt := &cos.ImageSearchOptions{
MatchThreshold: 60,
}
res, _, err := c.CI.ImageSearch(context.Background(), "pic/car.jpg", opt)
log_status(err)
fmt.Printf("%+v\\n", res)

参数说明

type ImageSearchOptions struct {
MatchThreshold int `url:"MatchThreshold,omitempty"`
Offset int `url:"Offset,omitempty"`
Limit int `url:"Limit,omitempty"`
Filter string `url:"Filter,omitempty"`
}
参数名称
参数描述
类型
是否必填
MatchThreshold
出参 Score 中,只有超过 MatchThreshold 值的结果才会返回。默认为0
int
Offset
起始序号,默认值为0
int
Limit
返回数量,默认值为10,最大值为100
int
Filter
针对入库时提交的 Tags 信息进行条件过滤。支持>、>=、<、<=、=、!=,多个条件之间支持 AND 和 OR 进行连接
string

结果说明

调用 ImageSearch 函数,会解析 api 返回的 xml 内容到 ImageSearchResult 结构,具体返回参数可查看 图片搜索接口 文档。