Last time, I registered an image using the import function of Image Search. With the import function, only the parameters for V1 can be registered, and the parameters newly added for V2 cannot be registered ~~. ** It's done. I'm sorry. ** **
So, I think it's better to register using API to input data to Image Search. There are some points to be aware of when registering data, so I would like to describe those points.
This time, we will register using the Java SDK. Please refer to [Search] for environment construction.
SimpleAdd.java
package imagesearch.sample;
import java.io.InputStream;
import java.util.Base64;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.imagesearch.model.v20190325.AddImageRequest;
import com.aliyuncs.imagesearch.model.v20190325.AddImageResponse;
import com.aliyuncs.imagesearch.model.v20190325.AddImageResponse.PicInfo;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
public class SimpleAdd {
/** AccessKey */
private static final String ACCESS_KEY = "XXXXXXXXXXXXXxxx";
/** SeacretKey */
private static final String KEY_SEACRET = "YYYYYYYYYYYYYYY";
public static void main(String[] args) throws Exception {
//Initialization(Tokyo region case
DefaultProfile.addEndpoint("ap-northeast-1", "ImageSearch", "imagesearch.ap-northeast-1.aliyuncs.com");
IClientProfile profile = DefaultProfile.getProfile("ap-northeast-1", ACCESS_KEY, KEY_SEACRET);
IAcsClient client = new DefaultAcsClient(profile);
AddImageRequest request = new AddImageRequest();
request.setInstanceName("itemsearch");
request.setProductId("id-0001");
request.setPicName("item0001");
request.setCategoryId(9);
request.setCrop(true);
request.setIntAttr(1000);
request.setStrAttr("Furniture: chair");
request.setCustomContent("{'sample': 'sample'}");
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream is = loader.getResourceAsStream("item01.jpg ");
String image = Base64.getEncoder().encodeToString(is.readAllBytes());
request.setPicContent(image);
AddImageResponse response = client.getAcsResponse(request);
// Debug
boolean checkShowJsonItemName = response.checkShowJsonItemName();
Integer code = response.getCode();
String message = response.getMessage();
String requestId = response.getRequestId();
Boolean success = response.getSuccess();
PicInfo picInfo = response.getPicInfo();
Integer categoryId = picInfo.getCategoryId();
String region = picInfo.getRegion();
System.out.printf("requestId:%s%nmessage:%s%ncheckShowJsonItemName:%s%ncode:%s%nsuccess:%s%n", requestId, message, checkShowJsonItemName, code, success);
System.out.println("PicInfo");
System.out.printf("\tcategoryId:%s%n\tregion:%s%n", categoryId, region);
}
}
requestId:F009FFA3-D94C-4C95-A8D1-957F7EE06591
message:success
checkShowJsonItemName:false
code:0
success:true
PicInfo
categoryId:9
region:140,474,36,578
ProductId
request.setProductId(productId);
Input Required. Supports product IDs up to 512 characters. You can include multiple images in one product.
PicName
request.setPicName(picName);
Input Required. Supports image names up to 512 characters.
By registering multiple images for one product, you can improve the accuracy of the search. I think it is good to register some pattern images such as front image and diagonal image.
CategoryId
request.setCategoryId(9);
Input is optional. Image category.
Configurable categories
Category ID | Description |
---|---|
0 | tops |
1 | dress |
2 | Bottoms |
3 | bag |
4 | shoes |
5 | Accessories |
6 | snack |
7 | Makeup |
8 | Bottle drink |
9 | furniture |
20 | toy |
21 | underwear |
22 | Digital equipment |
88888888 | Other |
PicContent
request.setPicContent(encodePicContent);
Input Required. Base64-encoded image content. Supports images up to 2 MB in size and a send latency of 5 seconds. Currently only jpg and png image formats are supported. Both vertical and horizontal pixels must be between 200 and 1024, and the image cannot contain rotation information.
In production operation, it may be better to include conversion logic before registration. Also, I don't know what it means to "support a transmission wait time of 5 seconds" here. .. .. what do you want. If anyone knows, please let me know. (I will check it in the source soon ...)
Crop
request.setCrop(true);
Input is optional. Whether subject recognition is necessary, the default is true.
In the case of product search, I think true is fine. For example, if you want to search for something like the atmosphere of a room, you may register with false.
Region
request.setRegion("280,486,232,351");
Input is optional. The subject range of the image in the format x1, x2, y1, y2, x1, y1 is the upper left point, x2, y2 is the lower right point. If the user sets a Region, the search will be performed in that Region regardless of the value of the Crop parameter.
When there are multiple objects in the image to be registered (for example, when trying to register a chair and a curtain or table is also shown), by setting the position information of the target object in order to improve the accuracy of the search, You can improve the accuracy of the search.
IntAttr
request.setIntAttr(intAttr);
Input is optional. An integer attribute that can be used for filtering when searching, this field is returned when searched. For example, you can set IntAttr for each site image / user image, and filter them when they are searched.
Parameters that can be used for filters added from V2. It is now possible to filter in combination with StrAttr, which will be described later. By using a filter, you can get data that matches the filter conditions from Image Search. Previously, it was convenient because I had to filter after getting the data. If you ask, it would be helpful if you could set multiple values. .. .. The filter conditions are ">,> =, <, <=, =". If you set the price of the product, I think that you can narrow down the product to 10,000 yen to 30,000 yen, which is common on EC sites.
StrAttr
request.setStrAttr(strAttr);
Input is optional. Supports string type attributes, up to 128 characters. It can be used for filtering when searched. This field is returned when searched.
Here you can set a string and filter it. The filter condition that can be used is "=,! =". Moreover, it is a filter with an exact match. It's pretty inconvenient. .. .. A realistic way to use it is to convert the parameters into bits and set them. .. .. It's still difficult to use. It would be very helpful if you could use multiple parameter settings and regular expressions.
CustomContent
request.setCustomContent("custom");
Input is optional. Supports user-customized content, up to 4096 characters. This field is returned when searched. For example, you can add text such as an image description.
You can make it easier to use by setting JSON etc.
System Limits-User Guide | Alibaba Cloud Document Center https://jp.alibabacloud.com/help/doc-detail/74408.htm
Here are some things to keep in mind when registering.
The points to be careful are as follows
Recommended Posts