Synchronous detection
This topic describes the API and parameters for synchronous image detection. You can use this information to build HTTP requests to detect tags in images.
Usage notes
API operation: /green/image/scan
You can submit a synchronous image detection task to detect and return the main tags in an image. The top N tags are returned in descending order of confidence level. For more information about how to construct an HTTP request, see Request structure. You can also use a pre-built HTTP request. For more information, see SDK overview.
This is a paid API operation. For more information about billing, see Content Moderation Pricing.
Detection duration
The maximum detection time for a synchronous task is 6 seconds. If a task exceeds this limit, the system returns a timeout error. If you do not require real-time results, you can use asynchronous detection. Otherwise, you can use synchronous detection, which is simpler to call. You should set the timeout period to 6 seconds for synchronous detection calls.
-
The image URL must use the HTTP or HTTPS protocol.
-
Supported image formats: PNG, JPG, JPEG, BMP, GIF, and WEBP.
-
The image size cannot exceed 20 MB for both synchronous and asynchronous calls. The height or width cannot exceed 30,000 pixels (px), and the total number of pixels cannot exceed 250 million (px).
NoteFor GIF images, the total number of pixels cannot exceed 4,194,304 (px), and the height or width cannot exceed 30,000 pixels (px).
-
The image must be downloaded within 3 seconds. If the download time exceeds 3 seconds, a download timeout error is returned.
-
For optimal performance, we recommend that the image resolution be at least 256x256 pixels. A lower resolution may affect the detection accuracy.
-
The response time of the image detection API depends on the image download time. Ensure that the storage service where the image is stored is stable and reliable. For best performance, use Alibaba Cloud Object Storage Service (OSS) or a Content Delivery Network (CDN).
QPS limit
The queries per second (QPS) limit for this API is 50 per user. Exceeding this limit triggers throttling, which can impact your business. Plan your calls accordingly.
Request parameters
For information about the common request parameters that must be included in a request, see Common parameters.
| Name | Type | Required | Example | Description |
| bizType | String | No | default | This field identifies your business scenario. You can create a business scenario in the Content Moderation console. For more information, see Customize moderation rules. |
| scenes | StringArray | Yes | ["tag"] | The detection scenario. Set the value to tag. |
| tasks | JSONArray | Yes | The detection tasks. Each element in the JSON array is a task struct. You can submit up to 100 tasks at a time. To submit 100 tasks, you must set the number of concurrent tasks to 100 or more. For more information about the structure of each element, see task. |
| Name | Type | Required | Example | Description |
| dataId | String | No | test35T5XhMsXfV4xKwUv8Ob74-1poXxF | The data ID. Make sure that all data IDs are unique in a request. |
| url | String | Yes | http://www.aliyundoc.com/2015/0826/2015082612403321.jpg | The URL of the image to detect. |
Return data
For more information about the response, see Return results.
| Name | Type | Example | Description |
| code | Integer | 200 | The error code. It is the same as the HTTP status code. For more information, see Common error codes. |
| msg | String | OK | The message returned for the request. |
| dataId | String | test35T5XhMsXfV4xKwUv8Ob74-1poXxF | The dataId from the request. |
| taskId | String | vi636L2Z$Q43i6LRrWdITWhq-1poXxF | The ID of the detection task. |
| url | String | http://www.aliyundoc.com/2015/0826/2015082612403321.jpg | The URL from the request. |
| extras | Map | xxx | Additional parameters. Note This parameter is subject to change. Do not rely on its return value. |
| results | Array | The detection results. If the call is successful (`code=200`), this array contains one or more `result` objects. For more information about the structure, see result. |
| Name | Type | Example | Description |
| scene | String | tag | The image detection scenario. The value is tag. |
| label | String | tag | The classification of the detection result. Valid values:
|
| suggestion | String | review | The recommended action. Valid values:
|
| rate | Float | 99.91 | The confidence level of the classification. The value ranges from 0.00 to 100.00. A higher value indicates a higher probability. |
| tagData | Object | The tag data that is returned when tags are detected (`label=tag`). For more information about the structure, see tagData. |
| Name | Type | Example | Description |
| summary | Array | A summary of the tag information. For more information about the structure, see summary. |
| Name | Type | Example | Description |
| tgCnName | String | Aircraft | The name of the tag in Chinese. |
| tgEnName | String | Aircraft | The name of the tag in English. |
| cnCategory | String | xxx | The name of the tag category in Chinese. |
| enCategory | String | xxx | The name of the tag category in English. |
| rate | Float | 99.91 | The confidence level that the object is the specified tag. The value ranges from 0 to 100. A higher value indicates a higher probability. |
Examples
http(s)://[Endpoint]/green/image/scan
&<Common request parameters>
{
"scenes": ["tag"],
"tasks": [
{
"dataId": "test35T5XhMsXfV4xKwUv8Ob74-1poXxF",
"url": "http://www.aliyundoc.com/2015/0826/2015082612403321.jpg"
}
]
}{
"msg": "OK",
"code": 200,
"data": [
{
"msg": "OK",
"code": 200,
"dataId": "test35T5XhMsXfV4xKwUv8Ob74-1poXxF",
"results": [
{
"tagData": {
"summary": [
{
"rate": 37.72,
"tagEnName": "Aircraft",
"tagCnName": "Aircraft"
},
{
"rate": 31.93,
"tagEnName": "Hotel",
"tagCnName": "Hotel"
}
]
},
"rate": 99.91,
"suggestion": "review",
"label": "tag",
"scene": "tag"
}
],
"taskId": "vi636L2Z$Q43i6LRrWdITWhq-1poXxF",
"url": "http://www.aliyundoc.com/2015/0826/2015082612403321.jpg"
}
],
"requestId": "5CAED310-CC31-4E34-9EB5-3C2E741BB870"
}