Synchronous detection

Updated at:

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.

Image limits
  • 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).

    Note

    For 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.

The request body is a JSON object. The fields are described in the following table.
NameTypeRequiredExampleDescription
bizTypeStringNodefault

This field identifies your business scenario. You can create a business scenario in the Content Moderation console. For more information, see Customize moderation rules.

scenesStringArrayYes["tag"]The detection scenario. Set the value to tag.
tasksJSONArrayYesThe 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.
Table 1. task
NameTypeRequiredExampleDescription
dataIdStringNotest35T5XhMsXfV4xKwUv8Ob74-1poXxFThe data ID. Make sure that all data IDs are unique in a request.
urlStringYeshttp://www.aliyundoc.com/2015/0826/2015082612403321.jpgThe URL of the image to detect.

Return data

For more information about the response, see Return results.

The `data` field in the response body is a JSON array. Each element contains the following fields:
NameTypeExampleDescription
codeInteger200

The error code. It is the same as the HTTP status code.

For more information, see Common error codes.

msgStringOKThe message returned for the request.
dataIdStringtest35T5XhMsXfV4xKwUv8Ob74-1poXxFThe dataId from the request.
taskIdStringvi636L2Z$Q43i6LRrWdITWhq-1poXxFThe ID of the detection task.
urlStringhttp://www.aliyundoc.com/2015/0826/2015082612403321.jpgThe URL from the request.
extrasMapxxxAdditional parameters.
Note This parameter is subject to change. Do not rely on its return value.
resultsArrayThe 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.
Table 2. result
NameTypeExampleDescription
sceneStringtagThe image detection scenario. The value is tag.
labelStringtagThe classification of the detection result. Valid values:
  • normal: The image is normal and has no tags.
  • tag: The image contains tags.
suggestionStringreviewThe recommended action. Valid values:
  • pass: The image does not contain tags. No further action is required.
  • review: The image contains tags. Further action is recommended.
rateFloat99.91The confidence level of the classification. The value ranges from 0.00 to 100.00. A higher value indicates a higher probability.
tagDataObjectThe tag data that is returned when tags are detected (`label=tag`). For more information about the structure, see tagData.
Table 3. tagData
NameTypeExampleDescription
summaryArrayA summary of the tag information. For more information about the structure, see summary.
Table 4. summary
NameTypeExampleDescription
tgCnNameStringAircraftThe name of the tag in Chinese.
tgEnNameStringAircraftThe name of the tag in English.
cnCategoryStringxxxThe name of the tag category in Chinese.
enCategoryStringxxxThe name of the tag category in English.
rateFloat99.91The confidence level that the object is the specified tag. The value ranges from 0 to 100. A higher value indicates a higher probability.

Examples

Request example
http(s)://[Endpoint]/green/image/scan
&<Common request parameters>
{
  "scenes": ["tag"],
  "tasks": [
    {
      "dataId": "test35T5XhMsXfV4xKwUv8Ob74-1poXxF",
      "url": "http://www.aliyundoc.com/2015/0826/2015082612403321.jpg"
    }
  ]
}
Response example
{
  "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"
}