Updated on 2022-10-29 GMT+08:00

UAE ID Card OCR

Function

This API identifies and extracts text from images of UAE ID cards and converts the text into JSON format.

Figure 1 UAE ID Card example

Prerequisites

Before using UAE 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.

URI

POST https://{endpoint}/v2/{project_id}/ocr/emirates-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. For more details, see Endpoints.

project_id

Yes

Project ID, which can be obtained from Obtaining an Account ID and 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. Set either this parameter or url.

String

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 JPEG, 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. Set either this parameter or image.

String

URL of the image file

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.

side

No

String

  • front: front of an ID card
  • back: back of an ID card

If this parameter is left empty or not included, the system automatically recognizes whether the image is the front or back of an ID card. To ensure accuracy, set this parameter.

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

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

Table 5 Response parameters

Parameter

Type

Description

side

String

front: front of an ID card

back: back of an ID card

id_number

String

ID number

name_arabic

String

Name in Arabic

name

String

Name

nationality_arabic

String

Arabic nationality

nationality

String

Nationality

sex

String

Gender

date_of_birth

String

Date of birth

expiry_date

String

Date of expiry of the ID card

card_number

String

ID number

country_code

String

Code of the country where an ID card is issued

machinecode1

String

Machine code in the first line on the back of an ID card

machinecode2

String

Machine code in the second line on the back of an ID card

machinecode3

String

Machine code in the third line on the back of an 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.

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.

Request Example

  • Request example (Method 1: Use the image Base64 string.)
    POST  https://ocr.ae-ad-1.g42cloud.com/v2/{project_id}/ocr/emirates-id-card
    
    Request Header:
    Content-Type: application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
    Request Body: 
    {
        "image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAA..."
    }
  • Request example (Method 2: Use the image URL.)
    POST  https://ocr.ae-ad-1.g42cloud.com/v2/{project_id}/ocr/emirates-id-card
    
    Request Header:
    Content-Type: application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
    Request Body: 
    {
        "url":"https://BucketName.obs.xxxx.com/ObjectName"
    }

Example Response

Status code: 200

Successful response example (the front)

{
    "result": {
        "side": "front",
        "id_number": "784-XXXX-XXXXXXX-X", 
        "name": "XXX",     
        "name_arabic": "XXX",
        "nationality": "Egypt", 
        "nationality_arabic": "مصر",
        "confidence": { 
            "id_number": 0.9712, 
            "name": 0.9731,
            "name_arabic": 0.9234,
            "nationality": 0.9543
            "nationality_arabic": 0.9543,
        }
    }
}

Successful response example (the back)

{
    "result": {
        "side": "back",
        "card_number": "XXXX-XXX-XX", 
        "laser_number": "XXXX-XXXXXXX-XX", 
        "confidence": {
            "id_number": 0.9999, 
            "laser_number": 0.9994
        }
    }
}

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.