Updated on 2024-07-11 GMT+08:00

Cambodian ID Card

Function

This API detects 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 and Limitations. For details about how to use this API, see Introduction to OCR.

Constraints and Limitations

  • Currently, only the front of an ID card can be recognized each time.
  • Only images in PNG, JPG, BMP, or TIFF format can be recognized.
  • No side of the image can be smaller than 15 or larger than 8,192 pixels.
  • An ID card can be rotated to any angle.
  • Illuminated or dark images can be recognized, but the accuracy may be compromised.

Calling Method

For details, see Calling APIs.

Prerequisites

Before using this API, subscribe to 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 you have not subscribed to the service yet, error "ModelArts.4204" will be displayed when you call this API. Before you call the API, log in to the OCR console and subscribe to the corresponding service. Ensure that you make the subscription to the service in the same region where you want to call this API.

URI

POST /v2/{project_id}/ocr/cambodian-idcard

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 by referring to 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 call 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 console, 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 will be categorized under the corresponding enterprise project for that ID.
  • If an enterprise project ID that is in the correct format but does not actually exist is carried, and the OCR service can be used properly, the bills will display the corresponding non-existent enterprise project ID.
  • If no enterprise project ID or an enterprise project ID with incorrect format (such as special characters) is carried, and the OCR service can be used properly, the bills will be categorized under default.
Table 3 Request body parameters

Parameter

Mandatory

Type

Description

image

No

String

Set either this parameter or url. Base64-encoded string of an image file. 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

No

String

Set either this parameter or image. Image URL. Currently, the following URLs are supported:

  • Public 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.
  • The URL cannot contain Chinese characters. If Chinese characters exist, they must be encoded using UTF-8.

return_portrait_image

No

Boolean

Whether to return the portrait. The options are:

  • true: The Base64-encoded string of the portrait on the ID card will be returned.
  • false: The Base64-encoded string will not be returned. If not passed in, the default value false is used.

return_portrait_location

No

Boolean

Whether to return the location of the portrait on the travel permit. The options are:

  • true: The location of the portrait on the ID card will be returned.
  • false: The location of the portrait will not be returned. If not passed in, the default value false is used.

return_idcard_type

No

Boolean

Whether to return the ID card type. The options are:

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

detect_border_integrity

No

Boolean

Whether to return the alarm result for ID card border integrity. The options are:

  • true: The alarm function will be enabled.
  • false: The alarm function will be disabled.

detect_blocking_within_border

No

Boolean

Whether to return the alarm result for blocked ID cards within their borders. The options are:

  • true: The function of generating an alarm when a blocked ID card is detected is enabled.
  • false: The function of generating an alarm when a blocked ID card is detected is disabled.

detect_blur

No

Boolean

Whether to return the alarm result for blurry ID cards. The options are:

  • true: The function of generating an alarm when a blurry ID card is detected is enabled.
  • false: The function of generating an alarm when a blurry ID card is detected is disabled.

detect_glare

No

Boolean

Whether to return the alarm result for glaring ID cards. The options are:

  • true: The function of generating an alarm when a glaring ID card is detected is enabled.
  • false: The function of generating an alarm when a glaring ID card is detected is disabled.

return_adjusted_image

No

Boolean

Whether to return the Base64-encoded string of the original ID card image. The options are:

  • true: The Base64-encoded string will be returned.
  • false: The Base64-encoded string will not be returned.

detect_tampering

No

Boolean

Whether to return the alarm result for tampered ID card portraits. The options are:

  • true: The alarm function is enabled.
  • false: The alarm function is disabled.

The alarm function does not work if the ID card image has undergone minor edits using a photo editing software.

Response Parameters

Status code: 200

Table 4 Response body parameter

Parameter

Type

Description

result

CambodianIdCardResult object

Recognition result

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

Table 5 CambodianIdCardResult

Parameter

Type

Description

id_number

String

ID 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 returned 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 returned only when idcard_type is set to true. The options are as follows:

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

adjusted_image

String

Base64-encoded string of the original ID card image. This parameter is returned only when return_adjusted_image is set to true.

detect_border_integrity_result

Boolean

Whether ID card borders are complete. true: The borders are incomplete. false: The borders are complete. This parameter is returned only when detect_border_integrity is set to true.

detect_blocking_within_border_result

Boolean

Whether the ID card is blocked within its borders. true: The ID card is blocked within its borders. false: The ID card is not blocked within its borders. This parameter is returned only when detect_blocking_within_border is set to true.

detect_blur_result

Boolean

Whether the ID card image is blurry. true: The image is blurry. false: The image is clear. This parameter is returned only when detect_blur is set to true.

detect_glare_result

Boolean

Alarm result for glaring ID cards. true: The ID card is glaring. false: The ID card is not glaring. This parameter is returned only when detect_glare is set to true.

detect_tampering_result

Boolean

Alarm result for whether the portrait on the ID card has been tampered with. true: The portrait has been tampered with. false: The portrait has not been tampered with. This parameter is returned only when detect_tampering is set to true.

score_info

CambodianIdCardScoreInformationResult object

Alarm scores, including idcard_type_score, border_integrity_score, blocking_within_border_score, blur_score, glare_score, and tampering_score. The value range of these parameters is [0, 99].

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.

Table 6 CambodianIdCardScoreInformationResult

Parameter

Type

Description

idcard_type_score

Integer

Alarm score. The value range of this parameter is [0, 99]. If the value is greater than 50, the ID card is a copy, while a value of 50 or less indicates it is the original. The closer the value is to 99, the more likely it is a copy, and the closer it is to 0, the more likely it is the original. This parameter is returned only when return_idcard_type is set to true.

border_integrity_score

Integer

Alarm score. The value range of this parameter is [0, 99]. If the value is greater than 50, the borders are incomplete, while a value of 50 or less indicates the borders are complete. The closer the value is to 99, the more likely the borders are incomplete, and the closer it is to 0, the more likely the borders are complete. This parameter is returned only when detect_border_integrity is set to true.

blocking_within_border_score

Integer

Alarm score. The value range of this parameter is [0, 99]. If the value is greater than 50, the ID card is blocked within its borders, while a value of 50 or less indicates the ID card is not blocked within its borders. The closer the value is to 99, the more likely the ID card is blocked within its borders, and the closer it is to 0, the more likely the ID card is not blocked within its borders. This parameter is returned only when detect_blocking_within_border is set to true.

blur_score

Integer

Alarm score. The value range of this parameter is [0, 99]. If the value is greater than 50, the ID card is blurry, while a value of 50 or less indicates the ID card is clear. The closer the value is to 99, the more likely the ID card is blurry, and the closer it is to 0, the more likely the ID card is clear. This parameter is returned only when detect_blur is set to true.

glare_score

Integer

Alarm score. The value range of this parameter is [0, 99]. If the value is greater than 50, the ID card is glaring, while a value of 50 or less indicates the ID card is not glaring. The closer the value is to 99, the more likely the ID card is glaring, and the closer it is to 0, the more likely the ID card is not glaring. This parameter is returned only when detect_glare is set to true.

tampering_score

Integer

Alarm score. The value range of this parameter is [0, 99]. If the value is greater than 50, the portrait on the ID card is tampered with, while a value of 50 or less indicates the portrait is not tampered with. The closer the value is to 99, the more likely the portrait is tampered with, and the closer it is to 0, the more likely the ID card is not tampered with. This parameter is returned only when detect_tampering is set to true.

Status code: 400

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

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

This parameter is not returned for a successful call.

error_msg

String

Error message when the API call fails

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

Example Request

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

Status code: 200

Example response for a successful request

{
"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 response for a failed request

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

Example SDK Code

The example SDK code is as follows:

You are advised to update the SDKs to the latest versions before use to prevent the local outdated SDKs from being unable to use the latest OCR functions.

  • Transfer the Base64 code of the Cambodian ID card image for recognition.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.ocr.v1.region.OcrRegion;
    import com.huaweicloud.sdk.ocr.v1.*;
    import com.huaweicloud.sdk.ocr.v1.model.*;
    
    
    public class RecognizeCambodianIdCardSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            OcrClient client = OcrClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(OcrRegion.valueOf("<YOUR REGION>"))
                    .build();
            RecognizeCambodianIdCardRequest request = new RecognizeCambodianIdCardRequest();
            CambodianIdCardRequestBody body = new CambodianIdCardRequestBody();
            body.withImage("/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA...");
            request.withBody(body);
            try {
                RecognizeCambodianIdCardResponse response = client.recognizeCambodianIdCard(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • Transfer the URL of the Cambodian ID card image for recognition.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.ocr.v1.region.OcrRegion;
    import com.huaweicloud.sdk.ocr.v1.*;
    import com.huaweicloud.sdk.ocr.v1.model.*;
    
    
    public class RecognizeCambodianIdCardSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            OcrClient client = OcrClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(OcrRegion.valueOf("<YOUR REGION>"))
                    .build();
            RecognizeCambodianIdCardRequest request = new RecognizeCambodianIdCardRequest();
            CambodianIdCardRequestBody body = new CambodianIdCardRequestBody();
            body.withUrl("https://BucketName.obs.myhuaweicloud.com/ObjectName");
            request.withBody(body);
            try {
                RecognizeCambodianIdCardResponse response = client.recognizeCambodianIdCard(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • Transfer the Base64 code of the Cambodian ID card image for recognition.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    # coding: utf-8
    
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkocr.v1.region.ocr_region import OcrRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkocr.v1 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.getenv("CLOUD_SDK_AK")
        sk = os.getenv("CLOUD_SDK_SK")
    
        credentials = BasicCredentials(ak, sk) \
    
        client = OcrClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(OcrRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = RecognizeCambodianIdCardRequest()
            request.body = CambodianIdCardRequestBody(
                image="/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..."
            )
            response = client.recognize_cambodian_id_card(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • Transfer the URL of the Cambodian ID card image for recognition.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    # coding: utf-8
    
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkocr.v1.region.ocr_region import OcrRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkocr.v1 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.getenv("CLOUD_SDK_AK")
        sk = os.getenv("CLOUD_SDK_SK")
    
        credentials = BasicCredentials(ak, sk) \
    
        client = OcrClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(OcrRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = RecognizeCambodianIdCardRequest()
            request.body = CambodianIdCardRequestBody(
                url="https://BucketName.obs.myhuaweicloud.com/ObjectName"
            )
            response = client.recognize_cambodian_id_card(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • Transfer the Base64 code of the Cambodian ID card image for recognition.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        ocr "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := ocr.NewOcrClient(
            ocr.OcrClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.RecognizeCambodianIdCardRequest{}
    	imageCambodianIdCardRequestBody:= "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..."
    	request.Body = &model.CambodianIdCardRequestBody{
    		Image: &imageCambodianIdCardRequestBody,
    	}
    	response, err := client.RecognizeCambodianIdCard(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • Transfer the URL of the Cambodian ID card image for recognition.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        ocr "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := ocr.NewOcrClient(
            ocr.OcrClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.RecognizeCambodianIdCardRequest{}
    	urlCambodianIdCardRequestBody:= "https://BucketName.obs.myhuaweicloud.com/ObjectName"
    	request.Body = &model.CambodianIdCardRequestBody{
    		Url: &urlCambodianIdCardRequestBody,
    	}
    	response, err := client.RecognizeCambodianIdCard(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

For more SDK code examples in various programming languages, see the Sample Code tab on the right of the API Explorer page, which can automatically generate corresponding SDK code examples.

Status Codes

Status Code

Description

200

Example response for a successful request

400

Example response for a failed request

See Status Codes.

Error Codes

See Error Codes.