Skip to main content

IDCard OCR

Extract ID CARD information from an image or photo. Currently only Thai ID Card is supported. Confidence score is scored from the OCR result.

info

Confidence score is -1.0 when the value of each validation field is False.

IDCard OCR

Extract ID CARD information from an image or photo. Currently only Thai ID Card is supported.

Response Definition

HTTP StatusError CodeError MessageDescription
200--Document information extraction successfully.
206206Partial ContentThe API was unable to retrieve information on some image or page content. In case request images or pages greater than one.
400400Bad requestNot a valid image request (must be .jpg, .jpeg, .png, .pdf) or invalid size, request schema. The API cannot retrieve information on any image.
41320000The request image base64 is too large.The requested image size is larger than the specified image size.
42220001The base64 image is incompatible.The Base64 image is incompatible and cannot be decoded.
500internal_server_errorInternal server errorSome errors occurred inside the server.

Request Options

Option KeyTypeDescription
censor_fieldList[str]Censor source image based on given input fields, e.g. ["id_number","title_name_surname_th"]
image_file_conversionstrConvert document to another format: "jpeg" | "origin" | "pdf" | "png" | "tiff"
return_faceboolDetect face on ID card
return_genderboolExtract gender from title
return_signedboolDetect signature on top of document's images
do_field_validationboolEnable field validation
return_datetime_isoboolEnable date time ISO format for date time fields

Response Keys

KeyTypeDescription
statusstrThe summary status.
errorList[dict]The list of errors which occurred during extracting information in each image or page.
dataList[dict]The response dictionary for each individual request page or image.

Response Error Keys

KeyTypeDescription
objectstrShow status "error".
codestrError code corresponding to error.
messagestrError detail.

Response Data Keys

Each field in the response data follows the Object Information V3 schema:

KeyTypeDescription
valuestrThe string value of the field.
bboxesList[List[List[int]]]The list of OCR bounding boxes in the document.
bboxes_normList[List[List[float]]]The list of OCR bounding boxes in normalized scale [0, 1].
confidencefloatThe OCR confidence level.

Data fields:

KeyDescription
id_numberID card number
title_name_surname_thFull Thai name (title + name + surname)
title_name_enEnglish title and first name
surname_enEnglish surname
dob_thDate of birth (Thai)
dob_enDate of birth (English)
religionReligion
address_1Address line 1
address_2Address line 2
address_fullFull address
address_house_building_numberHouse/building number
address_street_addressStreet address
address_sub_districtSub-district
address_districtDistrict
address_provinceProvince
address_postcodePostcode
doi_thDate of issue (Thai)
doi_enDate of issue (English)
doe_thDate of expiry (Thai)
doe_enDate of expiry (English)
title_thThai title
name_thThai first name
surname_thThai surname
title_enEnglish title
name_enEnglish first name

Optional Fields

Returned under the option key when the corresponding request option is enabled.

KeyTypeDescription
facebase64The extracted facial image from ID card.
genderstrThe gender prediction from ID card information.
signedboolWhether there is a signature over copied ID card documents.
processed_imagebase64Enabled when the optional censor_field input is provided.

Extract ID card information

POST https://api.aigen.online/aiscript/idcard/v3

Request Body

NameTypeDescription
imageStringBase64 image encoded string
optionOptional[dict]Specify optional features like
{
  censor_field:[field_array]
  return_face: true,
  ...
}

Responses

View Response
{
"status": "success",
"error": [],
"data": [
{
"id_number": {
"bboxes": [[[857, 238], [1418, 239], [1416, 307], [855, 307]]],
"bboxes_norm": [[[0.4357, 0.1803], [0.7209, 0.1811], [0.7199, 0.2326], [0.4347, 0.2326]]],
"value": "0000000000000",
"confidence": -1.0
},
"title_name_surname_th": {
"bboxes": [[[589, 317], [1504, 318], [1502, 419], [587, 418]]],
"bboxes_norm": [[[0.2994, 0.2402], [0.7646, 0.2409], [0.7636, 0.3174], [0.2984, 0.3167]]],
"value": "นาย ตัวอย่าง บัตรประชาชน",
"confidence": 0.9863
},
"title_name_en": {
"bboxes": [[[761, 435], [1109, 436], [1108, 503], [760, 503]]],
"bboxes_norm": [[[0.3869, 0.3295], [0.5638, 0.3303], [0.5633, 0.3811], [0.3864, 0.3811]]],
"value": "MR. TUAYANG",
"confidence": 0.9946
},
"surname_en": {
"bboxes": [[[885, 510], [1277, 511], [1275, 575], [883, 574]]],
"bboxes_norm": [[[0.4499, 0.3864], [0.6492, 0.3871], [0.6482, 0.4356], [0.4489, 0.4348]]],
"value": "BUDPRACHACHON",
"confidence": 0.999
},
"dob_th": {
"bboxes": [[[830, 582], [1171, 583], [1169, 648], [829, 647]]],
"bboxes_norm": [[[0.422, 0.4409], [0.5953, 0.4417], [0.5943, 0.4909], [0.4215, 0.4902]]],
"value": "14 ก.พ. 2531",
"confidence": 0.9961
},
"dob_en": {
"bboxes": [[[963, 657], [1312, 658], [1311, 722], [962, 721]]],
"bboxes_norm": [[[0.4896, 0.4977], [0.667, 0.4985], [0.6665, 0.547], [0.4891, 0.5462]]],
"value": "14 Feb. 1988",
"confidence": 0.9966
},
"religion": {},
"address_1": {
"bboxes": [[[281, 791], [1176, 794], [1174, 900], [279, 896]]],
"bboxes_norm": [[[0.1429, 0.5992], [0.5979, 0.6015], [0.5968, 0.6818], [0.1418, 0.6788]]],
"value": "ที่อยู่ 17/1 หมู่ที่ 9 ต.ตัวอย่าง อ. ตัวอย่าง",
"confidence": 0.981
},
"address_2": {
"bboxes": [[[282, 890], [506, 891], [505, 960], [281, 959]]],
"bboxes_norm": [[[0.1434, 0.6742], [0.2572, 0.675], [0.2567, 0.7273], [0.1429, 0.7265]]],
"value": "จ.ตัวอย่าง",
"confidence": 0.9878
},
"address_full": {
"bboxes": [
[[281, 791], [1176, 794], [1174, 900], [279, 896]],
[[282, 890], [506, 891], [505, 960], [281, 959]]
],
"bboxes_norm": [
[[0.1429, 0.5992], [0.5979, 0.6015], [0.5968, 0.6818], [0.1418, 0.6788]],
[[0.1434, 0.6742], [0.2572, 0.675], [0.2567, 0.7273], [0.1429, 0.7265]]
],
"value": "17/1 หมู่ที่ 9 ต.หัวไผ่ อ.เมืองอ่างทอง จ.อ่างทอง",
"confidence": 0.969
},
"address_house_building_number": {
"value": "17/1",
"confidence": 0.9689
},
"address_street_address": {
"value": "หมู่ที่ 9",
"confidence": 0.9689
},
"address_sub_district": {
"value": "ต.หัวไผ่",
"confidence": 0.969
},
"address_district": {
"value": "อ.เมืองอ่างทอง",
"confidence": 0.969
},
"address_province": {
"value": "จ.อ่างทอง",
"confidence": 0.969
},
"address_postcode": {},
"doi_th": {
"bboxes": [[[283, 968], [532, 969], [531, 1017], [282, 1016]]],
"bboxes_norm": [[[0.1439, 0.7333], [0.2705, 0.7341], [0.27, 0.7705], [0.1434, 0.7697]]],
"value": "14 ก.พ. 2561",
"confidence": 0.9946
},
"doi_en": {
"bboxes": [[[285, 1059], [541, 1060], [540, 1111], [284, 1110]]],
"bboxes_norm": [[[0.1449, 0.8023], [0.275, 0.803], [0.2745, 0.8417], [0.1444, 0.8409]]],
"value": "14 Feb. 2011",
"confidence": 0.9961
},
"doe_th": {
"bboxes": [[[1043, 959], [1293, 960], [1292, 1010], [1042, 1008]]],
"bboxes_norm": [[[0.5302, 0.7265], [0.6573, 0.7273], [0.6568, 0.7652], [0.5297, 0.7636]]],
"value": "13 ก.พ. 2570",
"confidence": 0.9966
},
"doe_en": {
"bboxes": [[[1049, 1053], [1301, 1054], [1300, 1100], [1048, 1099]]],
"bboxes_norm": [[[0.5333, 0.7977], [0.6614, 0.7985], [0.6609, 0.8333], [0.5328, 0.8326]]],
"value": "13 Feb. 2017",
"confidence": 0.9946
},
"title_th": {
"value": "นาย",
"confidence": 0.9863
},
"name_th": {
"value": "ตัวอย่าง",
"confidence": 0.9863
},
"surname_th": {
"value": "บัตรประชาชน",
"confidence": 0.9863
},
"title_en": {
"value": "MR.",
"confidence": 0.9946
},
"name_en": {
"value": "TUAYANG",
"confidence": 0.9946
},
"option": {
"face": {},
"gender": {},
"signed": {},
"processed_image": {}
}
}
]
}

Example Code

import requests

api = "https://api.aigen.online/aiscript/idcard/v3"
headers = {"x-aigen-key": "<key>"}
data = {
"image": "base64_image",
"option": {} #optional
}
res = requests.post(api, json=data, headers=headers)
print(res.json())