全部产品
Search
文档中心

图像搜索:根据图片查询图片

更新时间:Aug 10, 2023

本文为您介绍SearchImageByPic的语法及示例,用于根据图片查询图像搜索实例中的图片信息。

使用说明

本接口用于根据图片查询图像搜索实例中的图片信息。

说明 如需了解更多产品详情和获取技术支持,请单击在线咨询或通过钉钉群(35035130)联系我们。

QPS限制

查询操作默认的最大访问频率可在控制台中查看,为您购买时所选择的访问频次(QPS),当前支持1QPS、5QPS、10QPS。

SDK版本说明

图像SDK版本升级到V3.1.1,可使用“多主体识别”、“相似性分数”功能。请参见Java SDK

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

请求参数

名称 类型 是否必选 示例值 描述
Action String SearchImageByPic

系统规定参数。取值:SearchImageByPic。

InstanceName String demoinstance1

图搜实例名称。最多支持20个字符。

如果已经购买图搜实例可登录图像搜索管控台查看。

如果没有购买图搜实例可参考开通服务创建实例

说明 这里的实例名称并非实例ID,使用时请区分。
PicContent String AAAANSUhEUgAAAPcAAAEVCAYAAAA8d3NuAAAAAXNSR0IArs......RK5CYII=

图片内容。

  • 图片大小要求不超过4 MB。
  • 图片格式:PNG、JPG、JPEG、BMP、GIF、WEBP、TIFF、PPM。
  • 传输等待时间不超过5秒。

  • 服务类型为商标图片搜索时,图片长和宽像素要求大于等于200PX且小于4096PX。
  • 服务类型为布料图片搜索时,图片长和宽像素要求大于等于448PX且小于等于4096PX。

  • 服务类型为商品图片搜索和通用图片搜索时,图片长和宽像素要求大于等于100PX且小于等于4096PX。

  • 图片中不能包含旋转信息。
说明
  • 使用SDK方式调用:
    • 如使用V3版本SDK,则无需填写PicContent字段,SDK已将本字段封装为PicContentObject字段并自动转化为Base64编码。具体示例参考JAVA SDK
    • SDK不支持客户直接传递图片URL,V3版本SDK提供了一种变相实现URL上传的方式。具体示例参考JAVA SDK
  • 使用阿里云OpenAPI平台调用:
    • 如使用2019-03-25版本,PicContent字段请填写图片的Base64编码。
    • 如使用2020-12-14版本,在PicContent字段直接点击上传图片即可。
CategoryId Integer 88888888

商品类目。具体请参见类目参考

  • 对于商品搜索,如果设置类目,则以设置的为准;如果不设置类目,则由系统进行类目预测,预测的类目结果可以在Response中获取 。

  • 对于通用搜索,不论是否设置类目,系统会将类目设置为88888888。

Crop Boolean true

是否需要进行主体识别。默认true。

  • 为true时,由系统进行主体识别,以识别的主体进行搜索,主体识别结果可在Response中获取。
  • 为false时,则不进行主体识别,以整张图进行搜索。

Region String 280,486,232,351

图片的主体区域,格式为x1,x2,y1,y2, 其中x1,y1 是左上角的点,x2,y2是右下角的点。

说明
  • 若用户设置了Region,则不论Crop参数为何值,都将以用户输入Region进行搜索。

Num Integer 10

返回结果的数目。取值范围:1~100。默认值为10。

Start Integer 0

返回结果的起始位置。取值范围:0~499。默认值为0。

Filter String int_attr=1000 AND str_attr="value1"

过滤条件。int_attr支持的操作符有大于号(>)、大于等于号(>=)、小于号(<)、小于等于号(<=)、等于号(=)。str_attr支持的操作符有等于号(=)和不等号(!=),多个条件之支持AND和OR进行连接。

例如:

  • int_attr >= 100。
  • str_attr != "value1"。
  • int_attr = 1000 AND str_attr = "value1"。
说明 最多支持256个字符。

返回数据

名称 类型 示例值 描述
Msg String success

错误信息。

Head Object

搜索结果概述信息。

DocsFound Integer 10

返回结果数目。

DocsReturn Integer 10000

实例中命中结果数目。

SearchTime Integer 95

搜索耗时,单位毫秒。

RequestId String B3137727-7D6E-488C-BA21-0E034C38A879

请求ID。

Auctions Array of Auction

所有返回的商品描述信息。

ProductId String 2092061_1

商品ID。

PicName String 2092061_1.jpg

图片名称。

CategoryId Integer 8888888

图片类目。

SortExprValues String 5.37633353624177e+24;0

系统打分信息。

说明
  • 当前字段已弃用,建议使用Score。
  • SortExprValues是一个分号分隔的二元组,第一个值表示图片的相关性分数,值越大表示和查询的图片相关性越高。由于算法模型不同。
  • 当类目为0~2时,SortExprValues值域范围:0~7.33136443711219e+24。
  • 类目为其他值时,SortExprValues值域范围:0~5.37633353624177e+24。当两个图片完全一样时,这个分值最大。
CustomContent String zidingyi

用户自定义的内容。

Score Float 1

图片相似打分。取值范围:0~1。

说明 需要版本升级至V3.1.1方可使用。
IntAttr Integer 2

整数类型属性。

IntAttr2 Integer 20

整数类型属性。

说明 2023年1月3号之后创建的实例才能使用。
StrAttr String 2

字符串类型属性。

StrAttr2 String test

字符串类型属性。

说明 2023年1月3号之后创建的实例才能使用。
Code Integer 0

错误码。

  • 0:成功。
  • 非0:失败。
PicInfo Object

类目预测、主体识别结果等信息。

Region String 280,486,232,351

主体识别结果。图片的主体区域,格式为x1,x2,y1,y2,其中 x1,y1 是左上角的点,x2,y2是右下角的点。若用户请求中指定了主体区域,则以请求中为准。

CategoryId Integer 88888888

类目预测结果。若用户请求中指定了类目,则以请求中为准。

MultiRegion Array of reg

主体识别结果集合。

说明 需要版本升级至V3.1.1方可使用。
Region String 280,486,232,351

主体识别结果。图片的主体区域,格式为x1,x2,y1,y2,其中 x1,y1 是左上角的点,x2,y2是右下角的点。若用户请求中指定了主体区域,则以请求中为准。

AllCategories Array of Category

系统支持的所有类目信息。

Name String other

类目名称。

Id Integer 88888888

类目ID。

Success Boolean true

请求是否成功。

示例

请求示例

{
        "InstanceName": "demoinstance",
        "PicContent": "${Base64ImageContent}"
}

正常返回示例

JSON格式

HTTP/1.1 200 OK
Content-Type:application/json

{
  "Auctions" : [ {
    "CategoryId" : 0,
    "PicName" : "demo",
    "SortExprValues" : "7.33136443711219e+24;0",
    "Score" : 1.0,
    "ProductId" : "demo"
  } ],
  "Head" : {
    "DocsReturn" : 1,
    "DocsFound" : 1,
    "SearchTime" : 155
  },
  "PicInfo" : {
    "CategoryId" : 0,
    "Region" : "111,697,113,774",
    "AllCategories" : [ {
      "Name" : "Tops",
      "Id" : 0
    }, {
      "Name" : "Dress",
      "Id" : 1
    }, {
      "Name" : "Bottoms",
      "Id" : 2
    }, {
      "Name" : "Bag",
      "Id" : 3
    }, {
      "Name" : "Shoes",
      "Id" : 4
    }, {
      "Name" : "Accessories",
      "Id" : 5
    }, {
      "Name" : "Snack",
      "Id" : 6
    }, {
      "Name" : "Makeup",
      "Id" : 7
    }, {
      "Name" : "Bottle",
      "Id" : 8
    }, {
      "Name" : "Furniture",
      "Id" : 9
    }, {
      "Name" : "Toy",
      "Id" : 20
    }, {
      "Name" : "Underwear",
      "Id" : 21
    }, {
      "Name" : "Digital device",
      "Id" : 22
    }, {
      "Name" : "Other",
      "Id" : 88888888
    } ],
    "MultiRegion" : [ {
      "Region" : "604,1814,451,1358"
    }, {
      "Region" : "843,1615,687,1138"
    } ]
  },
  "RequestId" : "D61D869E-E92A-447F-AD67-9234F999E516",
  "Msg" : "success",
  "Success" : true,
  "Code" : 0
}

错误码

HttpCode 错误码 错误信息 描述
400 BadRequest The request has invalid parameters. 无效的参数
400 InvalidInstance The specified instance name is invalid. 实例名错误
400 NoCaretSeperator The body content is missing the ^ separator. 请求body缺少特定符号
400 EmptyMeta The body content has an empty meta field. 请求body含有空的字段
400 InvalidMetaItem The meta field is invalid. 无效的元信息字段
400 NoPicList The body content is missing the pic_list parameter. 未指定pic_list字段
400 InvalidPicList The specified pic_list parameter is invalid. 无效的pic_list字段
400 InvalidCategory The specified category is invalid. 无效的类目id
400 OverflowMaxResultNum The specified number of total results exceeds the maximum of 500. 超过了最大的返回结果限制数500
400 OverflowMaxReturnNum The specified number of results for each request exceeds the maximum of 100. 单次返回数超过限制值100
400 InvalidNumParameter The specified parameter num is invalid. 无效的字段num
400 InvalidIntAttr The specified int_attr field is invalid. 无效的int过滤字段
400 UnsupportedPicFormat The specified image format is invalid. 无效的图片格式
400 InvalidFilterClause The specified filtering condition is invalid. 无效的过滤条件
400 InstanceOverQuota The number of items exceeds the limit. 实例的图片数量超过限制值
400 IncorrectOrientation The image contains incorrect rotation flags in the meta data. 图片包含不支持的旋转参数
400 UnsupportedPicPixels The specified pixels is not supported. 图片像素值不支持
403 NoPermission You are not authorized to perform this operation. 没有权限进行此操作,请先让管理员账号授权.
403 DeniedRequest Your request was denied due to instance flow control. 请求被限流
500 UnknownException An internal server error occurred. 未知异常
500 NetworkException A network error occurred. 内部错误:请求网络异常
500 UnsupportedInstanceType The instance type is not supported. 内部错误:不支持的实例类型
500 UnsupportedOperationType The specified action is not supported. 内部错误:不支持的action
500 AccessEngineFailed An error occurred while accessing the search engine. 内部错误:请求引擎失败
500 InternalOssError An internal OAS error occurred. 内部错误:请求内部算法错误
500 InternalSwiftError An internal SWIFT error occurred. 内部错误:请求内部消息队列错误
500 InternalTableStoreError An internal Table Store error occurred. 内部错误:请求特征存储错误

访问错误中心查看更多错误码。

错误码

请参见错误码