Help Center> Optical Character Recognition> API Reference> APIs> Exit-Entry Permit for Traveling to and from Hong Kong, Macao, and Taiwan
Updated on 2022-11-30 GMT+08:00

Exit-Entry Permit for Traveling to and from Hong Kong, Macao, and Taiwan

Function

This API identifies and extracts text from images of exit-entry permits and converts the text into a structured format. For details about the constraints on using this API, see Constraints. For details about how to use this API, see Introduction to OCR.

Prerequisites

Before using Exit-Entry Permit for Traveling to and from Hong Kong, Macao, and Taiwan OCR, you need to apply for the service and complete authentication. For details, see Subscribing to an OCR Service and Authentication.

Before using the service for the first time, you need to enable the service by clicking Subscribe. You only need to subscribe to the service once. If the service is not enabled, an error message with error code "ModelArts.4204" will be displayed when you call the service. Before calling the service, log in to the OCR console and enable the service. Ensure that the region where the service is enabled is the same as that where the service is called.

Debugging

You can debug this API through automatic authentication in API Explorer. API Explorer can automatically generate and debug sample SDK code.

API Explorer can be called in ap-southeast-1.

URI

POST https://{endpoint}/v2/{project_id}/ocr/exit-entry-permit

Table 1 URI parameters

Parameter

Mandatory

Description

endpoint

Yes

Endpoint, which is the request address for calling an API.

The endpoint varies depending on services in different regions. For more details, see Endpoints.

project_id

Yes

Project ID, which can be obtained from Obtaining a Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token

Used to obtain the permission to operate APIs. The token is the value of X-Subject-Token in the response header in Authentication.

Content-Type

Yes

String

MIME type of the request body. The value is application/json.

Enterprise-Project-Id

No

String

Enterprise project ID. OCR uses 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 page, click the enterprise project name, and obtain the enterprise project ID on the enterprise project details page.

For details about how to create an enterprise project, see Optical Character Recognition User Guide.

NOTE:

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

  • If a correct enterprise project ID is carried and the OCR service can be used properly, the bills are allocated to the enterprise project corresponding to the ID.
  • If an incorrect enterprise project ID is carried and the OCR service can be used properly, the enterprise project in the bills is allocated to Non-project.
  • If no enterprise project ID is carried and the OCR service can be used properly, the enterprise project in the bills is allocated to Non-project.
Table 3 Request body parameters

Parameter

Mandatory

Type

Description

image

No

String

Configure either this parameter or url.

Base64-encoded image file. The image file has a size limit of 10 MB.

No side of the image can be smaller than 15 or larger than 8,192 pixels. Only images in JPG, PNG, BMP, or TIFF format can be recognized.

An example is /9j/4AAQSkZJRgABAg.... If the image data contains an unnecessary prefix, the error "The image format is not supported" is reported.

url

No

String

Configure either this parameter or image.

Image URL. Currently, the following URLs are supported:

  • Public network HTTP/HTTPS URL.
  • URL provided by OBS. You need to be authorized to use OBS data, 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. OBS is recommended for storing image data.

return_portrait_image

No

Boolean

Whether to return the portrait. Value options are as follows:

  • true: The Base64 code of the portrait on the ID card will be returned.
  • false: The Base64 code of the portrait on the ID card will not be returned.

If this parameter is not specified, false is used by default. In this case, the Base64 code of the portrait on the ID card will not be returned.

return_portrait_location

No

Boolean

Whether to return the location of the portrait on the ID card. Value options are as follows:

  • true: The location of the portrait on the ID card will be returned.
  • false: The location of the portrait on the ID card will not be returned.

If this parameter is not specified, false is used by default. In this case, the location of the portrait on the ID card will not be returned.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

result

ExitEntryPermitResult object

Calling result of a successful API call

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

Table 5 ExitEntryPermitResult

Parameter

Type

Description

name

String

Name

name_en

String

Name in English

sex

String

Gender

birth_date

String

Date of birth

number

String

Permit number

issuing_authority

String

Issuing authority

issue_place

String

Place where the permit is issued

valid_period

String

Date of expiry

machine_code

String

Machine-readable code

portrait_image

String

Base64 code of the portrait. This parameter is available only when return_portrait_image is set to true.

portrait_location

Array<Array<Integer>>

Location of the portrait on the original image. This parameter is available only when return_portrait_location is set to true. The image is displayed in a list. The list contains the two-dimensional coordinates (x,y) of the four vertices in the portrait area. The origin of the coordinates is the upper left corner of the image. The x axis is horizontal, and the y axis is vertical.

type

String

Certificate type. Value options are as follows:

  • Exit-Entry Permit for Traveling to and from Hong Kong and Macao
  • Exit-Entry Permit for Traveling to and from Taiwan

side

String

Whether the front or back side of the permit is displayed. Value options are as follows:

  • front: front side
  • back: back side

endorsement_info_hk

ExitEntryPermitEndorsementInfo object

Hong Kong endorsement information. This field is returned only when the permit type is Exit-Entry Permit for Traveling to and from Hong Kong and Macao.

endorsement_info_mo

ExitEntryPermitEndorsementInfo object

Macao endorsement information. This field is returned only when the permit type is Exit-Entry Permit for Traveling to and from Hong Kong and Macao.

endorsement_info_tw

ExitEntryPermitEndorsementInfo object

Taiwan endorsement information. This field is returned only when the permit type is Exit-Entry Permit for Traveling to and from Taiwan.

confidence

ExitEntryPermitConfidence object

Confidence of each field

Table 6 ExitEntryPermitEndorsementInfo

Parameter

Type

Description

endorsement_type

String

Endorsement type

valid_round_trips

String

Number of valid round journeys on the endorsement

endorsement_valid_period

String

Date of expiry of the endorsement

remark

String

Endorsement remarks

issue_info

String

Endorsement issuing information

Table 7 ExitEntryPermitConfidence

Parameter

Type

Description

name

Float

Confidence of the name

name_en

Float

Confidence of the English name

birth_date

Float

Confidence of the birth date

sex

Float

Confidence of the gender

number

Float

Confidence of the permit number

valid_period

Float

Confidence of the validity period

issuing_authority

Float

Confidence of the issuing authority

issue_place

Float

Confidence of the place of issuance

machine_code

Float

Confidence of the machine code

type

Float

Confidence of a certificate type

side

Float

Confidence of information on the front and back sides of image of the permit

endorsement_info_hk

Object

Confidence of the Hong Kong endorsement information

endorsement_info_mo

Object

Confidence of the Macao endorsement information

endorsement_info_tw

Object

Confidence of Taiwan endorsement information

Status code: 400

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

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

If error code ModelArts.4204 is displayed, refer to Why Is a Message Stating "ModelArts.4204" Displayed When the OCR API Is Called?

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

error_msg

String

Error message when the API call fails

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

Example Requests

  • Request example (Method 1: Use the image Base64 string.)
    POST https://ocr.cn-north-1.myhuaweicloud.com/v2/<project_id>/ocr/exit-entry-permit
    Request Header:
    Content-Type: application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
    Request Body:
    { 
        "image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..." 
     }
  • Request example (Method 2: Use the image URL.)
    POST https://ocr.cn-north-1.myhuaweicloud.com/v2/<project_id>/ocr/exit-entry-permit
    Request Header:
    Content-Type: application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
    Request Body:
    { 
        "url":"https://BucketName.obs.myhwclouds.com/ObjectName" 
     }

Example Responses

Status code: 200

Example of a successful response (the front)

{
    "result":{
        "name": "Zhang San",
        "name_en": "ZHANG, SAN",
        "birth_date": "1970.12.21",
        "sex":"M",
        "number": "C319XXXXX",
        "valid_period": "2016.01.04 - 2026.01.03",
        "issuing_authority": "Bureau of Exit and Entry Administration of the Ministry of Public Security",
        "issue_place": "Guangdong",
        "machine_code": "CSCA3xxxxxxx<290xxxx<810xxxx<2",
        "type": "Exit-Entry Permit for Traveling to and from Hong Kong and Macao",
        "side": "front",
        "portrait_image": "/9j/4AAQSkZJRg…",
        "portrait_location": [
            [
                1174, 
                1326
            ], 
            [
                1378, 
                1294
            ], 
            [
                1416, 
                1534
            ], 
            [
                1212, 
                1566
            ]
      ],
        "confidence": {
            "name": 0.9254,
            "name_en": 0.9245,
            "birth_date": 0.9014,
            "sex": 0.9896,
            "number": 0.9741,
            "valid_period": 0.9542,
            "issuing_authority": 0.9635,
            "issue_place": 0.9749,
            "machine_code": 0.8945,
            "type": 0.9650,
            "side": 0.9785
        }
    }
}

Example of a successful response (the back)

{
    "result":{
        "type": "Exit-Entry Permit for Traveling to and from Hong Kong and Macao",
        "side": "back",
        "endorsement_info_hk": {
            "endorsement_type": "Individual visits (G)",
            "valid_round_trips": "Valid for double journey per visit",
            "endorsement_valid_period": "2014.04.21-2015.04.20",
            "remark": "Stay for no more than 7 days in Hong Kong",
            "issue_info": "4400-H001"
        },
        "endorsement_info_mo": {
            "endorsement_type": "Individual visits (G)",
            "valid_round_trips": "Valid for double journey per visit",
            "endorsement_valid_period": "2014.04.21-2015.04.20",
            "remark": "Stay for no more than 7 days in Macao",
            "issue_info": "4400-M001"
        },
        "confidence": {
            "type": 0.9650,
            "side": 0.9785,
            "endorsement_info_hk": {
            "endorsement_type": 0.9214,
            "valid_round_trips": 0.9852,
            "endorsement_valid_period": 0.9474,
            "remark": 0.9996,
            "issue_info": 0.9524
        },
        "endorsement_info_mo": {
            "endorsement_type": 0.9741,
            "valid_round_trips": 0.9598,
            "endorsement_valid_period": 0.9157,
            "remark": 0.9145,
            "issue_info": 0.9935
        }
    }
}

Status code: 400

Example of a failed response

{
    "error_code": "AIS.0103", 
    "error_msg": "The image size does not meet the requirements."
}

Status Codes

Status Code

Description

200

Success response

400

Failure response

For details about status codes, see Status Codes.

Error Codes

For details about error codes, see Error Codes.