Updated on 2022-08-08 GMT+08:00

Image Tagging (v2.0)

Function

Image Tagging can accurately identify hundreds of scenes, thousands of common objects, and dozens of tag types in natural images. It makes intelligent album management, photo retrieval and classification, and scene- or object-based advertising more intuitive. After you upload an image, Image Tagging returns the tags, tag types, and confidence scores of the image to you. Image Tagging also returns the location information of common objects in the image.

Compared with v1.0, v2.0 refines tag types and provides more return information. For example, v2.0 can return location information of common objects. In addition, v2.0 uses an upgraded model that provides higher recognition accuracy. Therefore, v2.0 is recommended.

Prerequisites

URI

URI format

POST /v2/{project_id}/image/tagging

Table 1 Description

Parameter

Mandatory

Description

project_id

Yes

Indicates the project ID.

Request Message

Table 2 describes the request parameters.
Table 2 Parameter description

Parameter

Mandatory

Type

Description

image

false

String

Configure either this parameter or url.

Indicates the Base64 character string converted from the image. The size cannot exceed 10 MB. The image resolution of the narrow sides must be greater than 15 pixels, and that of the wide sides cannot exceed 4096 pixels. The supported image formats include JPG, PNG, and BMP.

url

false

String

Configure either this parameter or image.

Indicates the URL of an image. The options are as follows:

  • HTTP/HTTPS URLs on the public network
  • OBS URLs. To use OBS data, authorization is required, including service authorization, temporary authorization, and anonymous public authorization.
NOTE:
  • The API response time depends on the image download time. If the image download takes a long time, the API call will fail.
  • Ensure that the storage service where the images to be detected reside is stable and reliable. OBS is recommended for storing image data.
  • The region of OBS must be consistent with that of Image Recognition.

language

false

String

zh: indicates that the language of the returned tag is Chinese.

en: indicates that the language of the returned tag is English.

The default value is zh.

limit

false

Integer

Indicates the maximum number of tags that can be returned. The default value is 50.

threshold

false

Float

Indicates the confidence threshold. The value ranges from 0 to 100. The default value is 60.

Response Message

Table 3 describes the response parameters.
Table 3 Parameter description

Parameter

Type

Description

result

JSON

Indicates the content of the image tag when the API is successfully called.

This parameter is not included when the API fails to be called.

tags

List

Indicates the list of tags.

confidence

String

Indicates the tag confidence. The float value is converted into a string and returned. The float value ranges from 0 to 100.

tag

String

Indicates the tag name in the selected language (currently, only Chinese and English are supported).

type

String

Indicates the tag type in the selected language (currently, only Chinese and English are supported).

i18n_tag

JSON

Indicates the internationalization field of the tag. (i18n is only an internationalization flag and has no special meaning.)

  • zh: Chinese
  • en: English

i18n_type

JSON

Indicates the internationalization field of the tag type. (i18n is only an internationalization flag and has no special meaning.)

  • zh: Chinese
  • en: English

instances

List

If this parameter is empty, there is no object bounding box.

If this parameter is not empty, it has the following fields:
  • bounding_box: location of the object bounding box
    • width: width of the bounding box, which is in float format
    • height: height of the bounding box, which is in float format
    • top_left_y: distance from the upper left corner of the bounding box to the vertical axis, which is in float format
    • top_left_x: distance from the upper left corner of the bounding box to the horizontal axis, which is in float format
  • confidence: tag confidence. The float value is converted into a string and returned. The float value ranges from 0 to 100.

error_code

String

Indicates the error code of a failed API call. For details, see Error Codes.

This parameter is not included when the API is successfully called.

error_msg

String

Indicates the error message of a failed API call.

This parameter is not included when the API is successfully called.

Examples

  • Example request (Method 1: Use a Base64-encoded image.)
    POST https://{{Endpoint of Image Recognition}}/v2/{project_id}/image/tagging
    
    Request Header:   
    Content-Type:application/json 
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...    
    
    Request Body: 
    { 
     "image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAcAAAAcgEyAAIAAAAUAAAAjodpAAQAAAABAAAApAAAANAACvyAAAAnEAAK/IAAACcQQWRvYmUgUGhvdG9zaG9wIENTMyBXaW5kb3dzADIwMTc6MTA6MjAgMTA6NDU6MzYAAAAAA6ABAAMAAAAB//8AAKACAAQAAAABAAALIKADAAQAAAABAAAGQAAAAAAAAAAGAQMAAwAAAAEABgAAARoABQAAAAEAAAEeARsABQAAAAEAAAEmASgAAwAAAAEAAgAAAgEABAAAAAEAAAEuAgIABAAAAAEAABAj...", 
      "threshold": 60 
    }  
  • Example request (Method 2: Use the URL redirecting to an image file.)
    POST https://{{Endpoint of Image Recognition}}/v2/{project_id}/image/tagging
       
    Request Header:  
    Content-Type:application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    
    Request Body:
    {
      "image":"",
      "url":"https://{{OBS path for storing images}}",
      "threshold": 60.0
    } 
  • Example successful response
    {
        "result":
        {
            "tags":
            [
                {
                    "confidence": "92.38",
                    "instances":
                    [
                        {
                            "bounding_box":
                            {
                                "height": 133.32496056189905,
                                "top_left_x": 53.134917332575874,
                                "top_left_y": 254.21347984900842,
                                "width": 117.5866567171537
                            },
                            "confidence": "92.38"
                        },
                        {
                            "bounding_box":
                            {
                                "height": 133.32496056189905,
                                "top_left_x": 53.134917332575874,
                                "top_left_y": 254.21347984900842,
                                "width": 117.5866567171537
                            },
                            "confidence": "90.38"
                        }
                    ],
                    "tag": "Person",
                    "i18n_tag":
                    {
                        "en": "Person",
                        "zh": "Chinese character for person"
                    },
                    "type": "Human",
                    "i18n_type":
                    {
                        "en": "Human",
                        "zh": "Chinese characters for human"
                    }
                },
                {
                    "confidence": "94.38",
                    "instances":
                    [],
                    "tag": "Book",
                    "i18n_tag":
                    {
                        "en": "Book",
                        "zh": "Chinese characters for book"
                    },
                    "type": "Education",
                    "i18n_type":
                    {
                        "en": "Education",
                        "zh": "Chinese characters for education"
                    }
                },
                {
                    "confidence": "92.38",
                    "instances":
                    [
                        {
                            "bounding_box":
                            {
                                "height": 133.32496056189905,
                                "top_left_x": 53.134917332575874,
                                "top_left_y": 254.21347984900842,
                                "width": 117.5866567171537
                            },
                            "confidence": "92.38"
                        }
                    ],
                    "tag": "Bed",
                    "i18n_tag":
                    {
                        "en": "Bed",
                        "zh": "Chinese character for bed"
                    },
                    "type": "Home category",
                    "i18n_type":
                    {
                        "en": "Home category",
                        "zh": "Chinese characters for home category"
                    }
                }
            ]
        }
    }
  • Example failed response
    {
        "error_code": "AIS.0014",
        "error_msg": "The JSON format of the input data is incorrect."
    }

Return Value

  • Normal

    200

  • Abnormal

    Return Value

    Description

    400

    • The request cannot be understood by the server due to malformed syntax. The client should not repeat the request without modifications.
    • The request parameter is incorrect.

    401

    The request requires user authentication.

    403

    No operation permission.

    404

    The server has not found anything matching the Request-URI.

    500

    The server encountered an unexpected condition which prevented it from fulfilling the request.

Error Codes

For details about error codes, see Error Codes.