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.
![](https://support.huaweicloud.com/intl/en-us/ae-ad-1-api-image/public_sys-resources/note_3.0-en-us.png)
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
- Before using Image Tagging, you need to apply for the service and complete authentication. For details, see Applying for a Service and Authentication.
URI
URI format
POST /v2/{project_id}/image/tagging
Parameter |
Mandatory |
Description |
---|---|---|
project_id |
Yes |
Indicates the project ID. |
Request Message
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:
NOTE:
|
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
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.)
|
i18n_type |
JSON |
Indicates the internationalization field of the tag type. (i18n is only an internationalization flag and has no special meaning.)
|
instances |
List |
If this parameter is empty, there is no object bounding box.
If this parameter is not empty, it has the following fields:
|
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
- 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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot