Updated on 2024-11-04 GMT+08:00

Image Moderation (V3)

Function

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

URI

POST /v3/{project_id}/moderation/image

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token

It is used to obtain the permission to call APIs. For details about how to obtain the token, see Authentication. The value of X-Subject-Token in the response header is the token.

Enterprise-Project-Id

No

String

Enterprise project ID. Moderation allows you to use Enterprise Project Management Service (EPS) to split fees for resources used by different user groups and users. To obtain the enterprise project ID, go to the Enterprise Project Management console, click the enterprise project name, and obtain the enterprise project ID on the enterprise project details page. For how to create an enterprise project, see Content Moderation User Guide.

After an enterprise project is created, parameter transfer involves the following scenarios:

  • If a correct enterprise project ID is carried and Content Moderation can be used properly, the bills will be categorized under the corresponding enterprise project for that ID.
  • If an enterprise project ID that is in the correct format but does not actually exist is carried, and Content Moderation can be used properly, the bills will display the corresponding non-existent enterprise project ID.
  • If no enterprise project ID or an enterprise project ID with incorrect format (such as special characters) is carried, and Content Moderation can be used properly, the bills will be categorized under default.
Table 3 Request body parameters

Parameter

Mandatory

Type

Description

event_type

No

String

Event type. The options are as follows:

  • head_image: avatar
  • album: album
  • dynamic: story
  • article: post
  • comment: comment
  • room_cover: room cover
  • group_message: group chat image
  • message: private chat image
  • product: product image
NOTE:
  • A group chat image contains chat messages of multiple people.
  • The event types are preset business scenarios. (Some scenarios may not be intercepted.)
    1. If you want to enable custom moderation, you can add custom moderation policies on the console.
    2. If you have special moderation requirements, contact us for adjustment by submitting a service ticket.

categories

No

Array of strings

Detection scenario. The following scenarios are supported:

  • terrorism: terrorism-related elements
  • porn: pornographic elements
  • image_text: advertisement in images and text

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

NOTE:

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

url

No

String

Configure either this parameter or image.

Image URL. Internet HTTP and HTTPS URLs are supported.

image

No

String

Configure either this parameter or url.

Base64-encoded string of the image file, which cannot be larger than 10 MB. The image cannot exceed 20 x 20 pixels. JPG, PNG, JPEG, WEBP, GIF, TIFF, TIF, and HEIF formats are supported.

language

No

String

Language of the text in the image, which can be Chinese (zh), English (en), or Arabic (ar). The default value is zh.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

request_id

String

Unique ID of the request, which is used for troubleshooting. You are advised to save the ID.

Minimum length: 2

Maximum length: 64

result

ImageDetectionResult object

Calling result of a successful API call. This parameter is not included when the API fails to be called.

Table 5 ImageDetectionResult

Parameter

Type

Description

suggestion

String

Whether the image passes the check

  • block: The image contains sensitive information and fails to pass the check.
  • pass: The image does not contain sensitive information and passes the check.
  • review: The image needs to be manually reviewed.

category

String

Level-1 label of the detection result. The following categories are supported:

  • terrorism: terrorism-related information
  • porn: pornographic information
  • image_text: image and text

details

Array of ImageDetectionResultDetail objects

Detection details

Table 6 ImageDetectionResultDetail

Parameter

Type

Description

suggestion

String

Whether the image passes the check

  • block: The image contains sensitive information and fails to pass the check.
  • pass: The image does not contain sensitive information and passes the check.
  • review: The image needs to be manually reviewed.

category

String

Level-1 label of the detection result. The following categories are supported:

  • terrorism: terrorism-related information
  • porn: pornographic information
  • image_text: image and text

confidence

Float

Confidence. The value ranges from 0 to 1. A larger value indicates a higher confidence.

face_location

FaceLocationDetail object

Face location. It is an array that has four values, indicating the coordinates of the upper left corner and lower right corner, respectively.

For example, in the value [207,522,340,567], 207 indicates the horizontal coordinate of the upper left corner, 522 indicates the vertical coordinate of the upper left corner, 340 indicates the horizontal coordinate of the lower right corner, and 567 indicates the vertical coordinate of the lower right corner.

label

String

Detected label

Table 7 FaceLocationDetail

Parameter

Type

Description

top_left_x

Integer

Horizontal coordinate of the upper left corner of detected face

top_left_y

Integer

Vertical coordinate of the upper left corner of detected face

bottom_right_x

Integer

Horizontal coordinate of the lower right corner of detected face

bottom_right_y

Integer

Vertical coordinate of the lower right corner of detected face

Table 8 QRLocationDetail

Parameter

Type

Description

top_left_x

Integer

Horizontal coordinate of the upper left corner of the detected QR code

top_left_y

Integer

Vertical coordinate of the upper left corner of the detected QR code

bottom_right_x

Integer

Horizontal coordinate of the lower right corner of the detected QR code

bottom_right_y

Integer

Vertical coordinate of the lower right corner of the detected QR code

Table 9 OCRTextDetail

Parameter

Type

Description

segment

String

Hit risk segment

glossary_name

String

Name of the hit custom word dictionary. This field is returned only when a custom word dictionary is hit.

Status code: 400

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

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

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

Minimum length: 8

Maximum length: 36

error_msg

String

Error message of a failed API call.

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

Minimum length: 2

Maximum length: 512

Example Request

endpoint is the request URL for calling an API. Endpoints vary depending on services and regions. For details, see Endpoints.

For example, if the service is deployed in the CN North-Beijing4 region, the endpoint is moderation.cn-north-4.myhuaweicloud.com and the request URL is https://moderation.cn-north-4.myhuaweicloud.com/v3/{project_id}/moderation/image. For details about how to obtain the project ID, see Obtaining a Project ID.

  • Use the Base64 code of an image to check whether the image contains sensitive information. Set event_type to head_image and categories to porn and terrorism.
    POST https://{endpoint}/v3/{project_id}/moderation/image
    
    {
      "event_type" : "head_image",
      "image" : "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAA...",
      "categories" : [ "porn", "terrorism" ]
    }
  • Use the URL an image to check whether the image contains sensitive information. Set event_type to head_image and categories to porn and terrorism.
    POST https://{endpoint}/v3/{project_id}/moderation/image
    {
      "event_type" : "head_image",
      "url" : "https://bucketname.obs.myhwclouds.com/ObjectName1",
      "categories" : [ "porn", "terrorism" ]
    }

Example Response

Status code: 200

Example successful response

{
  "request_id" : "53f9719c3730d1169e47403d5c8a9473",
  "result" : {
    "category" : "porn",
    "details" : [ {
      "category" : "porn",
      "confidence" : 0.9934315,
      "label" : "sexy_female",
      "suggestion" : "review"
    }, {
      "category" : "porn",
      "confidence" : 0.99798274,
      "label" : "intimacy",
      "suggestion" : "review"
    } ],
    "suggestion" : "review"
  }
}

Status code: 400

Example failed response

{
  "error_code" : "AIS.0402",
  "error_msg" : "The image format is not supported."
}

Status Codes

Status Code

Description

200

Example of a successful response

400

Example of a failed response