ID Card OCR

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

Response Definition

http status
error_code
error_message
error_parameters
description

200

200

success

-

OCR successful

400

001

no id card on image

-

Can't detect ID CARD on image

400

002

missing or invalid input

field <string>

Request is missing and input or invalid follow API specification

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

Extract ID card information

POST https://apis.aigen.online/aiscript/idcard/v1

Request Body

Name
Type
Description

image*

String

Base64 image encoded string

return_face

Boolean

​Default: false

Set true to enable return of facial image in UTF-8 Base64 format

return_gender

Boolean

​Default: false

Set true to return of the gender information

return_signed

Boolean

​Default: false

​Set true to enable detection of overlaying script on top of the document's photos or images

do_text_correct

Boolean

​Default: false

​Please specify “do_text_correct” is True if you need text validation on “id_number”, “religion”, “dob_th”, “dob_en”, “doi_th”, “doi_en”,” doe_th”, and “doe_en” fields.

{
  "error_code": "200",
  "error_message": "success",
  "error_parameters": {},
  "result": {
    "field": {
      "id_number": {
        "bbox": [
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ]
        ],
        "value": "123456789012",
        "valid": false,
        "error_message": [
          "expect length id number equal 13, got :10"
        ],
        "confidence": 0.99
      },
      "title_name_surname_th": {
        "bbox": [
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ]
        ],
        "value": "นาย ประกันภัย รวยมาก",
        "confidence": 0.99
      },
      "title_name_en": {
        "bbox": [
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ]
        ],
        "value": "Mr. Prakunpai",
        "confidence": 0.99
      },
      "surname_en": {
        "bbox": [
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ]
        ],
        "value": "Ruaymak",
        "confidence": 0.99
      },
      "dob_th": {
        "bbox": [
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ]
        ],
        "value": "1 ม.ค. 2530",
        "valid": true,
        "error_message": [],
        "standard_datetime": "1987-01-01T00:00:00+07:00",
        "confidence": 0.99
      },
      "dob_en": {
        "bbox": [
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ]
        ],
        "value": "1 Jan. 1987",
        "valid": true,
        "error_message": [],
        "standard_datetime": "1987-01-01T00:00:00+07:00",
        "confidence": 0.99
      },
      "religion": {
        "bbox": [
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ]
        ],
        "value": "พุทธ",
        "valid": true,
        "error_message": [],
        "confidence": 0.99
      },
      "address_1": {
        "bbox": [
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ]
        ],
        "value": "ที่อยู่่ 123 ถนนxxx แขวงxxx",
        "confidence": 0.99
      },
      "address_2": {
        "bbox": [
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ]
        ],
        "value": "เขตxxx กรุงเทพมหานคร",
        "confidence": 0.99
      },
      "doi_th": {
        "bbox": [
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ]
        ],
        "value": "1 ธ.ค. 2540",
        "valid": true,
        "error_message": [],
        "standard_datetime": "1997-12-01T00:00:00+07:00",
        "confidence": 0.99
      },
      "doi_en": {
        "bbox": [
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ]
        ],
        "value": "1 Dec. 1997",
        "valid": true,
        "error_message": [],
        "standard_datetime": "1997-12-01T00:00:00+07:00",
        "confidence": 0.99
      },
      "doe_th": {
        "bbox": [
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ]
        ],
        "value": "1 ธ.ค. 2565",
        "valid": true,
        "error_message": [],
        "standard_datetime": "2022-12-01T00:00:00+07:00",
        "confidence": 0.99
      },
      "doe_en": {
        "bbox": [
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ],
          [
            0,
            0
          ]
        ],
        "value": "1 Dec. 2022",
        "valid": true,
        "error_message": [],
        "standard_datetime": "2022-12-01T00:00:00+07:00",
        "confidence": 0.99
      }
    },
    "face": {
      "bbox": [
        [
          0,
          0
        ],
        [
          0,
          0
        ],
        [
          0,
          0
        ],
        [
          0,
          0
        ]
      ],
      "image_b64": "face_image_base64"
    },
    "gender": {
      "value": "M",
      "confidence": 0.99
    },
    "signed": {
      "value": true,
      "confidence": 0.99
    }
  },
  "response_id": "string"
}

​Example code

import requests

api = "https://apis.aigen.online/aiscript/idcard/v1"
headers = {"x-aigen-key": "<key>"}
data = {"image": "<base64_string>"}

res = requests.post(api, json=data, headers=headers)
print(res.json())

Last updated