Learn how to query images by using Image Search.
Background information
Image Search lets you query images by using the API, SDK (recommended), or console (for feature exploration).
Console method
-
Log in to the Image Search console.
-
Select the target service type and instance.
-
Click Image Search. On the Image Search tab, configure the search parameters on the left, and then click Confirm to search. The search results appear in JSON format in the Response parameters section on the right. The results include fields such as
score(similarity score),productId, andpicName.Parameter
API parameter
Description
Required
Search type
Type
The search type. Valid values:
-
SearchByPic: Searches for images similar to a provided image. This is the default option.
-
SearchByName: Searches for similar images by using a previously indexed image.
Yes
Upload image
PicContent
The content of the image, encoded in Base64. The image must meet the following requirements:
-
The image size cannot exceed 4 MB.
-
Supported formats: PNG, JPG, JPEG, BMP, GIF, WEBP, TIFF, and PPM.
-
The transfer latency cannot exceed 5 seconds.
-
For product image search and generic image search, the image height and width must be between 100 pixels and 4,096 pixels, inclusive.
-
The image cannot contain rotation information.
Yes
Subject identification
Crop
Specifies whether to perform subject identification on the uploaded image.
-
true: enables subject identification, including system automatic identification and custom subject identification. For more information, see the description of the Subject identification method parameter.
-
false: disables subject identification. The search uses the entire image.
Yes
Subject identification method
Not applicable
Specifies the method for subject identification.
-
System automatic identification: The system automatically identifies the subject and uses the identified subject for the search. The response includes the subject identification result.
-
Custom subject region: You can customize the subject region. The format is
x1,x2,y1,y2, wherex1,y1represents the upper-left corner andx2,y2represents the lower-right corner. Click this option and drag to select the subject region. If you do not specify a custom subject region, the search uses the entire image.
Yes
Image category
CategoryId
The image category. You can specify the category of an image during an image search. For more information, see Category reference.
Note-
For product search, if you specify a category, the service uses it. If you do not specify a category, the system performs category prediction. The response includes the predicted category.
-
For generic search, the service sets the category to 88888888, regardless of whether you specify a category.
No
Number of results
Num
The maximum number of similar results to return. Valid values: 1 to 100. Default value: 10.
No
Start position
Start
The start position of the returned similar results. Valid values: 0 to 499. Default value: 0.
Yes
Filter condition
Filter
You can specify conditions to filter the search results. For example, you can return only the image results where ownerId is 1000 or the company name is "alibaba".
Note-
int_attrsupports the operators >, >=, <, <=, =, in, and not in. -
str_attrsupports the operators =, !=, in, and not in. -
You can use AND and OR to connect multiple conditions.
-
Example:
int_attr=1000 AND str_attr="value1".
No
Similarity score filter
ScoreThreshold
If you specify a similarity score threshold, the service returns only images with a score greater than or equal to the threshold. The threshold can be a value from 0.00 to 1.00, with up to two decimal places. The default value is 0.00.
No
-
-
View the results.
The following table describes the response parameters.
Parameter
Type
Example
Description
Success
Boolean
true
Specifies whether the request was successful.
RequestId
String
36C43E96-8F68-44AA-B1AF-B1F7AB94A6C1
The request ID.
Code
Integer
0
The error code.
-
0: The request was successful.
-
A non-zero value indicates a failed request.
Message
String
success
The error message.
Head
-
-
Contains information about the search result.
└DocsReturn
Integer
10
The number of results returned.
└DocsFound
Integer
10000
The number of matched results in the instance.
└SearchTime
Integer
95
The search duration, in milliseconds.
PicInfo
-
-
Information about category prediction and subject identification results.
└CategoryId
Integer
88888888
The category prediction result. If you specified a category in the request, this parameter returns that category.
└Region
String
280,486,232,351
The subject identification result. This is the subject region of the image, in the format x1,x2,y1,y2. x1 and y1 represent the upper-left corner, and x2 and y2 represent the lower-right corner. If you specified a subject region in the request, this parameter returns that region.
└AllCategories
-
-
A list of all supported categories.
└└Name
String
Tops
The category name.
└└Id
Integer
0
The category ID.
└MultiRegion
-
-
A collection of subject identification results.
NoteThis parameter is available only in V3.1.1 and later.
└└Region
String
280,486,232,351
The subject identification result. This is the subject region of the image, in the format x1,x2,y1,y2. x1 and y1 represent the upper-left corner, and x2 and y2 represent the lower-right corner. If you specified a subject region in the request, this parameter returns that region.
Auctions
-
-
The descriptions of all returned products.
└CustomContent
String
Demo Custom Content
The custom content.
└PicName
String
DemoPic
The image name.
└CategoryId
Integer
0
The image category.
└ProductId
String
test
The product ID.
└SortExprValues
String
7.33136443711219e+24;0
The scoring information of the system.
NoteThis field is deprecated. We recommend that you use Score instead.
└Score
Float
1
The similarity score of the image. Value range: 0 to 1.
NoteThis parameter is available only in V3.1.1 and later.
└IntAttr
Integer
0
An integer attribute of the product.
└IntAttr2
Integer
0
An integer attribute of the product.
└IntAttr3
Integer
0
An integer attribute of the product.
└IntAttr4
Integer
0
An integer attribute of the product.
└StrAttr
String
demoStrAttr
A string attribute of the product.
└StrAttr2
String
demoStrAttr
A string attribute of the product.
└StrAttr3
String
demoStrAttr
A string attribute of the product.
└StrAttr4
String
demoStrAttr
A string attribute of the product.
-
API method
Through direct access via HTTP or HTTPS protocols, authentication is required using a signature mechanism, and the request body must be transmitted in a specified format. The QPS for querying similar images via API is determined by the purchased QPS plan. For more details, see Search for images by name or Search for images by image.
SDK method
Image Search provides various SDK versions, eliminating the need to handle complex settings like signature verification and request body assembly. The QPS for querying similar images via SDK is determined by the purchased QPS plan. For more details, see SDK reference.