Help Center > > API Reference> Moderation (Image)> Image Moderation

Image Moderation

Updated at: Nov 29, 2019 GMT+08:00

Function

This API analyzes and identifies whether the uploaded images contain political figures, pornographic elements, or terrorism-related content, and returns the result to you.

URI

URI format

POST /v1.0/moderation/image

Request Message

Table 1 describes the request parameters.

Table 1 Request parameters

Parameter

Mandatory

Type

Description

image

Configure either this parameter or url.

String

Indicates the Base64 character string converted from the image. The size cannot exceed 10 MB.

In the politics scenario, the face of a political figure must be greater than or equal to 50 x 50 pixels.

The supported image formats include JPG, PNG, and BMP.

url

Configure either this parameter or image.

String

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

  • HTTP/HTTPS URLs on the public network
  • HUAWEI CLOUD OBS URLs. To use OBS data, authorization is required, including service authorization, temporary authorization, and anonymous public authorization. For details, see Configuring the Access Permission of OBS.
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 image to be detected resides is stable and reliable. You are advised to use HUAWEI CLOUD OBS.

categories

No

Array

Indicates the detection scenario.

  • politics: checks whether political figures exist.
  • terrorism: checks whether terrorism-related content or sensitive political information exists.
  • porn: checks whether pornographic content exist.
  • ad: checks whether advertisements exist (in the open beta test).
  • all: checks all elements in the politics, terrorism, and porn scenarios.

You can set the parameter to the preceding values to check the corresponding elements.

If this parameter is left blank or does not exist, both politics and terrorism scenarios are checked, but the porn scenario is not included.

NOTE:

The number of detection times in each scenario is collected by category.

threshold

No

Number

Indicates the threshold for filtering the detection results. Only the results whose confidence score is greater than or equal to the threshold are displayed in the detail list. The value ranges from 0 to 1. If this parameter is left unspecified, the default values of different scenarios prevail.

The default value of the politics scenario is 0.95.

The default value of the terrorism scenario is 0.

The default value of the ad scenario is 0.

If there is no special requirement, do not pass this parameter, or leave this parameter unspecified as shown in the example request.

NOTE:
  • If the maximum confidence score of a specific detection scenario is smaller than the value of threshold, the detail list is empty. If the value of threshold is too small, too many results are displayed in the detail list.
  • The threshold parameter does not support filtering of the porn scenario.
  • The threshold parameter does not affect the suggestion in the response.

Response Message

Table 2 describes the response parameters.

Table 2 Response parameters

Parameter

Type

Description

result

Object

Indicates the calling result when the API is successfully called.

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

detail

Object

Indicates a list of detection results of a specific scenario. politics lists the detection results of political figures, terrorism lists the detection results of terrorism-related content or sensitive political information, and porn lists the detection results of pornographic elements. If the maximum confidence score of a specific detection scenario is smaller than the value of threshold, the detail list is empty.

confidence

Number

Indicates the confidence score. The value ranges from 0 to 1.

face_detail

Object

Indicates the facial information in the politics scenario, including the following four attributes:

h: indicates the height of the face area.

w: indicates the width of the face area.

x: indicates the distance from the upper left corner of the face area to the y axis.

y: indicates the distance from the upper left corner of the face area to the x axis.

label

String

Indicates the label of each detection result. Possible values are as follows:

In the politics scenario, label indicates the information about the corresponding political figure.

In the terrorism scenario, label indicates the information about the terrorism-related elements or sensitive political information.

  • Currently, the terrorism scenario supports the following labels:

    normal: indicates that the image does not contain terrorism-related elements.

    knife: indicates that the image contains a knife.

    gun: indicates that the image contains a gun.

    fire: indicates that the image contains the fire.

    bloody: indicates that the image contains a bloody scene.

    terrorist: indicates that the image contains a terrorist organization and symbol.

    fascist: indicates that the image contains a fascist organization and symbol.

    cult: indicates that the image contains a heretical organization and symbol.

    negative_politics: indicates that the image contains a negative political organization and symbol.

    negative_political_events: indicates that the image contains a sensitive political event and symbol.

    special_characters: indicates that the image contains special characters.

    kidnap: indicates that the image contains kidnapping.

    corpse: indicates that the image contains a corpse.

    riot: indicates that the image contains a riot.

    parade: indicates that the image contains a demonstration.

    sensitive_landmarks: indicates that the image contains a sensitive landmark.

    military_weapon: indicates that the image contains a military weapon.

    army: indicates that the image contains police force.

    positive_politics: indicates that the image contains a positive political organization and symbol.

    crowd: indicates that the image contains crowd.

In the porn scenario, label classifies pornographic elements (porn information or sexy information).

  • Currently, the porn scenario supports the following labels:

    normal: indicates that the image does not contain pornographic elements.

    porn: indicates that the image contains pornographic elements.

    sexy: indicates that the image contains suggestive content.

In the ad scenario, label indicates the advertisement detection result (common content or advertisement).

suggestion

String

Indicates whether the check is passed.

block: indicates that sensitive information is detected and the information fails to pass the check.

pass: indicates that no sensitive information is detected and the information passes the check.

review: indicates that the image needs to be manually reviewed.

NOTE:

When multiple scenarios are detected at the same time, the value of suggestion is subject to the scenario where sensitive information is most likely to be included. That is, if a block occurs in any scenario, the value of suggestion is block. If all scenarios pass the check, the value of suggestion is pass. In addition, if manual review is required in any scenario, the value of suggestion is review.

category_suggestion

Object

Indicates the check result of each scenario. Possible values are as follows:

block: indicates that sensitive information is detected and the information fails to pass the check.

pass: indicates that no sensitive information is detected and the information passes the check.

review: indicates that the image needs to be manually reviewed.

error_code

String

Indicates the error code when the API fails to be called. For details, see Error Code.

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

error_msg

String

Indicates the error message when the API fails to be called.

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

Examples

  • Example request (Method 1: Use a Base64-encoded image.)
    POST https://moderation.ap-southeast-1.myhuaweicloud.com/v1.0/moderation/image
        
    Request Header:      
    Content-Type:application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    Request Body:
    {  
       "url" : "",
       "image" : "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAA...",
       "categories":[  
          "politics",
          "terrorism"
       ],
       "threshold" : ""
    }
  • Example request (Method 2: Use the URL redirecting to the image file.)
    POST https://moderation.ap-southeast-1.myhuaweicloud.com/v1.0/moderation/image
        
    Request Header:      
    Content-Type:application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    Request Body:
    {  
    "url" : "https://BucketName.obs.myhuaweicloud.com/ObjectName",
       "image" : "",
       "categories":[  
          "politics",
          "terrorism"
       ],
       "threshold" : ""
    }
  • Example successful response
    {  
       "result":{
          "detail":{
             "politics":[
                {  
                   "confidence": 0.89155281782150264,
                   "face_detail":{
                       "h": 130,
                       "w": 103,
                       "x": 80,
                       "y": 125
                    },
                   "label": "xxx"
                },
                {
                   "confidence": 0.87563462432654422,
                   "face_detail":{
                       "h": 131,
                       "w": 203,
                       "x": 423,
                       "y": 109
                    },
                   "label": "yyy"
                }
             ],
             "terrorism":[
                {  
                   "confidence": 0.73155281782150264,
                   "label": "xxx"
                },
                {
                   "confidence": 0.26844718217849736,
                   "label": "yyy"
                }
             ]
          },
          "suggestion": "block",
          "category_suggestion": {
                "politics":"block",
                "terrorism":"review"
          }
       }
    }
  • Example failed response
    {
        "error_code": "AIS.0005",
        "error_msg": "The service does not exist."
    }

Status Code

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

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel