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

Recapture Detection

Function

As a statistical method in the retailing industry, barcodes are used to calculate retailers' sales volumes as the evidence of sales incentives. This API can recognize whether a barcode image is the original one or the one that is recaptured or printed for recapturing by using the deep neural network algorithm. It enables you to detect the invalid barcode images and makes the statistics more precise and valid.

Currently, only barcodes of Huawei products. For other service scenarios, submit a service ticket to reach technical support.

Prerequisites

  • Before using Recapture Detection, you need to apply for the service and complete authentication. For details, see Applying for a Service and Authentication.
  • By default, the maximum number of concurrent API calls is 1. To increase concurrency, contact Huawei technical support.

URI

URI format

POST /v1.0/image/recapture-detect

Request Message

Table 1 describes the request parameters.
Table 1 Parameter description

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 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 JPEG, PNG, BMP, and WEBP.

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 Access Permissions 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

Float

Indicates the threshold used to identify whether an image is real or fake. The default value is 0.95. The value ranges from 0 to 1. If you input a value beyond the value range, the default value is used.

scene

No

List

Indicates the detection scenario. Currently, only the recapture scenario is supported. This parameter can be left empty. If it is left empty, the detection results of all scenarios are returned.

Response Message

Table 2 describes the response parameters.
Table 2 Parameter description

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.

suggestion

String

Indicates the conclusion. Possible values are as follows:

  • true: indicates that the image is valid.
  • false: indicates that image is a fake one.
  • uncertainty: indicates that whether the image is valid or fake is uncertain.

category

String

Indicates the tag (if suggestion is true, the value will be a null string. Otherwise, the value will not be a null string).

recapture: indicates that the image is a recaptured one.

score

Float

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

detail

List

Indicates the recognition result details.

label

String

Indicates the tag value. Possible values are as follows:

  • original: indicates that the image is the original one.
  • recapture: indicates that the image is a recaptured one.

confidence

Float

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

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://image.ap-southeast-1.myhuaweicloud.com/v1.0/image/recapture-detect
       
    Request Header:  
    Content-Type:application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    
    Request Body:
    {
     "image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAcAAAAcgEyAAIAAAAUAAAAjodpAAQAAAABAAAApAAAANAACvyAAAAnEAAK/IAAACcQQWRvYmUgUGhvdG9zaG9wIENTMyBXaW5kb3dzADIwMTc6MTA6MjAgMTA6NDU6MzYAAAAAA6ABAAMAAAAB//8AAKACAAQAAAABAAALIKADAAQAAAABAAAGQAAAAAAAAAAGAQMAAwAAAAEABgAAARoABQAAAAEAAAEeARsABQAAAAEAAAEmASgAAwAAAAEAAgAAAgEABAAAAAEAAAEuAgIABAAAAAEAABAj...",
      "url": "",
      "threshold":0.99,
      "scene":["recapture"]
    }  
  • Example request (Method 2: Use the URL redirecting to an image file.)
    POST https://image.ap-southeast-1.myhuaweicloud.com/v1.0/image/recapture-detect
       
    Request Header:  
    Content-Type:application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    
    Request Body:
    {
      "image":"",
      "url":"https://<bucketName>.obs.<region>.myhuaweicloud.com/<objectName>",
      "threshold":0.99,
      "scene":["recapture"]
    } 
  • Example successful response
    {
      "result": {
        "suggestion": "false",
        "category": "recapture",
        "score": "0.9998",
        "detail": [
          {
            "label": "recapture",
            "confidence": "0.9998"
          }
        ]
      }
    }
  • Example failed response
    {
        "error_code": "AIS.0105",
        "error_msg": "Recognize Failed"
    }

Return Value

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

Error Codes

For details about error codes, see Error Codes.