Updated at: 2022-09-22 GMT+08:00

Cambodian ID Card

Function

This API identifies and extracts text from images of Cambodia-issued ID cards 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 Cambodian ID Card 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-3.

URI

POST https://{endpoint}/v2/{project_id}/ocr/cambodian-idcard

Table 1 URI 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. 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.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

image

No

String

Configure either this parameter or url.

Base64 code of an image. 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.

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

return_portrait_image

No

Boolean

Whether to return the Base64 code of the portrait on the ID card image. 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 position coordinates of the portrait on the ID card image. 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.

return_idcard_type

No

Boolean

Whether to return the ID card type. Value options are as follows:

  • true: The ID card type will be returned, indicating that the ID card is the original ID card or copy of the original ID card.
  • false: The ID card type will not be returned.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

result

CambodianIdCardResult object

Calling result of a successful API call

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

Table 5 CambodianIdCardResult

Parameter

Type

Description

id_number

String

ID card number

name_kh

String

Khmer name

name_en

String

Name in English

birth_date

String

Date of birth

sex

String

Gender

height

String

Height

birth_place

String

Place of birth

address

String

Addresses, separated by spaces

issue_date

String

Date of issue

expiry_date

String

Date of expiry

description

String

Personal features in the image

machine_code1

String

Machine code in the first line

machine_code2

String

Machine code in the second line

machine_code3

String

Machine code in the third line

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.

idcard_type

String

ID card type. This parameter is available only when idcard_type is set to true. Value options are as follows:

  • normal: original ID card
  • copy: copy of the ID card

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 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://{endpoint}/v2/{project_id}/ocr/cambodian-idcard
    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://{endpoint}/v2/{project_id}/ocr/cambodian-idcard
    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

{
"result": {
        "id_number": "XXXXX",
        "name_kh": "យឹXXXXX",
        "name_en": "YOENG THXXXXX",
        "birth_date": "១០.០៧.១៩៩៩",
        "sex": "ស្រី",
        "height": "១៥៨ ស.ម",
        "birth_place": "XXXXX",
        "address": " XXXXX",
        "issue_date": "១៥.១២.២០១៥",
        "expiry_date": "១៤.១២.២០២៥",
        "description": "XXXXXX",
        "machine_code1": "IDKHM040XXXXXXX<<<<<<<<<<<<<<<",
        "machine_code2": "990XXX2F25XXXXXXX<<<<<<<<<<<2",
        "machine_code3": "YOENG<<THXXXXX<<<<<<<<<<<<<<<",
         "idcard_type": "normal",
        "confidence": {
            "id_number": 0.8345,
            "name_kh": 0.8721,
            "name_en": 0.7191,
            "birth_date": 0.7749,
            "sex": 0.8216,
            "height": 0.6493,
            "birth_place": 0.8282,
            "address": 0.91185,
            "issue_date": 0.7509,
            "expiry_date": 0.7983,
            "description": 0.9091,
            "machine_code1": 0.9047,
            "machine_code2": 0.9292,
            "machine_code3": 0.898,
            "idcard_type": 0.998
        },
        "portrait_image": "/9j/4AA…. ",
        "portrait_location": [
            [
                53,
                341
            ],
            [
                185,
                340
            ],
            [
                179,
                504
            ],
            [
                42,
                505
            ]
        ]
    }
    }

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.

close