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

Image Clarity Detection

Function

This API only identifies whether the original image of an enterprise form is clear or blurred, helping enterprises build the image moderation system.

Prerequisites

By default, the maximum number of concurrent API calls is 3. To increase concurrency, contact Huawei technical support.

URI

URI format

POST /v1.0/moderation/image/clarity-detect

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

threshold

No

Number

Indicates the threshold for determining whether an image is clear. The value ranges from 0 to 1. If this parameter is left unspecified, the default value 0.8 prevails.

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.

category

String

Indicates the detection result.

  • clarity: indicates that the detected image is clear.
  • blur: indicates that the detected image is blurred.

detail

List

Indicates the check result details.

label

String

Indicates the detection label.

  • clarity: indicates the label for clear images.
  • blur: indicates the label for blurred images.

confidence

Number

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

error_code

String

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

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/clarity-detect
        
    Request Header:      
    Content-Type: application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    Request Body:
    {
     "image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAcAAAAcgEyAAIAAAAUAAAAjodpAAQAAAABAAAApAAAANAACvyAAAAnEAAK/IAAACcQQWRvYmUgUGhvdG9zaG9wIENTMyBXaW5kb3dzADIwMTc6MTA6MjAgMTA6NDU6MzYAAAAAA6ABAAMAAAAB//8AAKACAAQAAAABAAALIKADAAQAAAABAAAGQAAAAAAAAAAGAQMAAwAAAAEABgAAARoABQAAAAEAAAEeARsABQAAAAEAAAEmASgAAwAAAAEAAgAAAgEABAAAAAEAAAEuAgIABAAAAAEAABAj...",
    "url": "", 
    "threshold":0.8
    }
  • Example request (Method 2: Use the URL redirecting to the image file.)
    POST https://moderation.ap-southeast-1.myhuaweicloud.com/v1.0/moderation/image/clarity-detect
        
    Request Header:      
    Content-Type: application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    Request Body:
    {
     "image":"",
     "url":"https://BucketName.obs.myhuaweicloud.com/ObjectName",
     "threshold":0.8
    }
  • Example successful response
    {
      "result":{
          "category": "blur",
          "detail": [
           {
            "label":"clarity",
            "confidence":0.2907
           },
           {
            "label":"blur",
            "confidence":0.7093
           }
          ]
       }
    }
  • 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.