Help Center > > API Reference> APIs> Chile ID Card OCR

Chile ID Card OCR

Updated at: Sep 30, 2021 GMT+08:00

Function

Chile ID Card OCR recognizes the text in a Chile ID card image and returns the recognition result in JSON format. For details about the constraints on using this API, see Constraints. For details about how to use this API, see Introduction to OCR.

Figure 1 Chile ID Card OCR example

Prerequisites

Before using Chile ID Card OCR, you need to apply for the service and complete authentication. For details, see Subscribing to OCR 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.

URI

POST https://{endpoint}/v2/{project_id}/ocr/chile-id-card

Table 1 Path parameters

Parameter

Mandatory

Description

endpoint

Yes

Domain name or IP address of the server bearing the REST service endpoint. The endpoint varies depending on services in different regions. The endpoint of the Chile ID Card OCR API is ocr.la-south-2.myhuaweicloud.com.

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

During API authentication using a token, the token is added to requests to obtain permissions for calling the API. The value of X-Subject-Token in the response header is the obtained token.

Content-Type

Yes

String

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

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

image

Yes

String

Base64-encoded image data. 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.

url

Configure either this parameter or image.

String

URL of the image file. Currently, URLs for anonymously and publicly authorized or external access to image files stored on OBS are supported.

Response Parameters

Response parameters and status codes vary in different recognition results. They are described as below.

Status code: 200

Table 4 Response parameters

Parameter

Type

Description

result

Object

Calling result of a successful API call

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

Table 5 Response parameters

Parameter

Type

Description

surname

List

Last name

given_name

String

First name

nationality

String

Nationality

sex

String

Gender

birth

String

Date of birth

issue_date

String

Date of issue

expiry_date

String

Date of expiry

document_number

String

Document number

number

String

ID number

confidence

Object

Confidence of a field. The value ranges from 0 to 1.

A higher confidence indicates a higher accuracy of the field identified.

The confidence is calculated using algorithms and is not equal to the accuracy.

Status code: 400

Table 6 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 included when the API is successfully called.

error_msg

String

Error message returned when the API fails to be called

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

Request Example

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

    For example, the endpoint of Chile ID Card OCR deployed in the LA-Santiago region is ocr.la-south-2.myhuaweicloud.com. The request URL is https://ocr.la-south-2.myhuaweicloud.com/v2/{project_id}/ocr/chile-id-card. project_id indicates the project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

  • For details about how to obtain a token, see Making an API Request.
  • Request example (Method 1: Use the image Base64 string.)
    POST https://ocr.la-south-2.myhuaweicloud.com/v2/{project_id}/ocr/chile-id-card
    
    Request Header: 
    Content-Type: application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
    Request Body:
    {
        "image": "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgA..."
    }
  • Request example (Method 2: Use the image URL.)
    POST https://ocr.la-south-2.myhuaweicloud.com/v2/{project_id}/ocr/chile-id-card
    
    Request Header:
    Content-Type: application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
    Request Body: 
    {
        "url":"https://BucketName.obs.xxxx.com/ObjectName"
    }
  • Sample code for a Python 3 request (For codes in other languages, refer to the following sample or use OCR SDK.)
    # encoding:utf-8
    
    import requests
    import base64
    
    url = "https://ocr.la-south-2.myhuaweicloud.com/v2/{project_id}/ocr/chile-id-card"
    token = "Actual token value obtained by the user"
    headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}
    
    imagepath = r'./data/myanmar-driver-license-demo.png'
    with open(imagepath, "rb") as bin_data:
        image_data = bin_data.read()
    image_base64 = base64.b64encode(image_data).decode("utf-8")  # Base64 encoding of images.
    payload = {"image": image_base64} # url or image.
    response = requests.post(url, headers=headers, json=payload)
    print(response.text)

Example Response

Status code: 200

Successful response example

{
   "result": {
        "surname": [
            "FERNANDEZ",
            "GATICA"
        ],
        "given_name": "MARCELA CAROLINA",
        "nationality": "CHILENA",
        "sex": "F",
        "birth": "21 FEB 1982",
        "document_number": "100000001",
        "issue_date": "1 SEP 2013",
        "expiry_date": "10 AGO 2023",
        "number": "12.749.625-K",
        "confidence": {
             "surname": 0.9584,
             "given_name": 0.8106,
             "nationality": 0.7026,
             "sex": 0.5879,
             "birth": 0.9305,
             "document_number": 0.8181,
             "issue_date": 0.8518,
             "expiry_date": 0.7757,
             "number": 0.9528
        }
   }
}

Status code: 400

Failure response example

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

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel