Updated on 2024-03-27 GMT+08:00

Distortion Correction

Function

This API only identifies whether the original image of an enterprise form is distorted, and corrects the distortion.

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/distortion-correct

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.

correction

No

Boolean

Indicates whether to perform image distortion correction.

  • true: indicates that image distortion correction will be performed. It is the default value.
  • false: indicates that image distortion correction will not be performed.

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.

distortion

Boolean

Indicates the identification result.

  • true: indicates that the image is distorted.
  • false: indicates that the image is not distorted.

data

String

Indicates the image after distortion correction, which is a Base64 character string converted from the image.

If the image is not distorted, no distortion correction is required, or the output parameter indicates that no distortion correction is required. In this case, the return value is a null string.

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/distortion-correct
        
    Request Header:      
    Content-Type: application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    Request Body:
    {
     "image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAcAAAAcgEyAAIAAAAUAAAAjodpAAQAAAABAAAApAAAANAACvyAAAAnEAAK/IAAACcQQWRvYmUgUGhvdG9zaG9wIENTMyBXaW5kb3dzADIwMTc6MTA6MjAgMTA6NDU6MzYAAAAAA6ABAAMAAAAB//8AAKACAAQAAAABAAALIKADAAQAAAABAAAGQAAAAAAAAAAGAQMAAwAAAAEABgAAARoABQAAAAEAAAEeARsABQAAAAEAAAEmASgAAwAAAAEAAgAAAgEABAAAAAEAAAEuAgIABAAAAAEAABAj...",
    "url": "", 
    "correction":true
    }
  • Example request (Method 2: Use the URL redirecting to the image file.)
    POST https://moderation.ap-southeast-1.myhuaweicloud.com/v1.0/moderation/image/distortion-correct
        
    Request Header:      
    Content-Type: application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    Request Body:
    {
     "image":"",
     "url":"https://BucketName.obs.myhuaweicloud.com/ObjectName",
     "correction":true
    }
  • Example successful response
    {
      "result":{
          "distortion": true,
          "data": "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAA..."
       }
    }
  • 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.