Tutorials
FPT.AI Reader - Vietnamese ID Card Recognition
API Usage Guide
Authentication
To authorize, users can use the following code:
import requests
API_ENDPOINT = "https://api.fpt.ai/vision/idr/vnm"
auth = {'api_key': 'generated_API_key'}
r = requests.post(API_ENDPOINT, files=/path/to/image/file, headers=auth)
# Pass api_key into header with cURL command
curl -X POST
https://api.fpt.ai/vision/idr/vnm
-H "api_key: generated_API_key"
The system has been connected to FPT Gateways, therefore, users need to create an account on Console and then generate an API key in order to send requests to the gateway (by default each new API key can only make 50 requests).
The API key needs to be embedded in the header of all API requests as follows:
api_key: generated_API_key
Recognition of Vietnamese ID card from form-data image file
import requests
API_ENDPOINT = "https://api.fpt.ai/vision/idr/vnm"
auth = {'api_key': 'generated_API_key'}
file = {'image': open(/path/to/image/file, 'rb')}
r = requests.post(API_ENDPOINT, files=file, headers=auth)
# Pass api_key into header with cURL command
curl -X POST
https://api.fpt.ai/vision/idr/vnm
-H "api_key: generated_API_key"
-F image=@/path/to/image/file
This is the method of using the system by sending a form-data Vietnamese ID card image to the API endpoint. Users need to set the key image for the image file in the body of the request.
Instructions to send the request using the software POSTMAN as follows:
Header
Body
Recognition of Vietnamese ID card from URL
import requests
API_ENDPOINT = "https://api.fpt.ai/vision/idr/vnm"
payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data;
name=\"image_url\"\r\n\r\nlink/to/image\r\n
------WebKitFormBoundary7MA4YWxkTrZu0gW--"
auth = {
'content-type': "multipart/form-data;
boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
'api_key': "generated_API_key"}
response = requests.request("POST", API_ENDPOINT, data=payload, headers=auth)
# Pass api_key into header with cURL command
curl -X POST
https://api.fpt.ai/vision/idr/vnm
-H "api_key: generated_API_key"
-F "image_url=/link/to/image"
This is the method of using the system by sending a link contained Vietnamese ID card image to the API endpoint. Users need to set the key image_url for the link in the body of the request.
Instructions to send the request using the software POSTMAN are as follows:
Body
Recognition of Vietnamese ID card from base64 string
import requests
API_ENDPOINT = "https://api.fpt.ai/vision/idr/vnm"
payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data;
name=\"image_base64\"\r\n\r\nstring/base64/of/image/goes/here\r\n
------WebKitFormBoundary7MA4YWxkTrZu0gW--"
auth = {
'content-type': "multipart/form-data;
boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
'api_key': "generated_API_key"}
response = requests.request("POST", API_ENDPOINT, data=payload, headers=auth)
# Pass api_key into header with cURL command
curl -X POST
https://api.fpt.ai/vision/idr/vnm
-H "api_key: generated_API_key"
-F "image_base64=/string/base64/of/image"
This is the method of using the system by sending the Vietnamese ID card image in form base64 string to the API endpoint. Users need to set the key image_base64 for the base64 string in the body of the request.
Instructions to send the request using the software POSTMAN are as follows:
Body
Extract Vietnamese ID card and recognition of human face on image
import requests
API_ENDPOINT = "https://api.fpt.ai/vision/idr/vnm"
payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data;
name=\"image\";
filename=\"/path/to/image/file\"\r\nContent-Type:
image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\n
Content-Disposition: form-data;
name=\"face\"\r\n\r\n1\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"
auth = {
'content-type': "multipart/form-data;
boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
'api_key': "generated_API_key"}
response = requests.request("POST", API_ENDPOINT, data=payload, headers=auth)
# Pass api_key into header with cURL command
curl -X POST
https://api.fpt.ai/vision/idr/vnm
-H "api_key: generated_API_key"
-F image=@/path/to/image/file
-F face=1
This is a feature of the system in order to extract the cropped image of the Vietnamese ID card and the photocard based on the algorithms Object Detection and Face Recognition.
To use this feature, in addition to the regular keys such as image, image_url and image_base64 as described above, customers need to set an additional key face with the value equals to 1 in the body of the request.
After sending the request successfully, cropped_idcard and face will be added in the returned result as links to the cropped image of the Vietnamese ID card and the identity photo (see picture below). For several security reasons, these links will only be availabe within 5 minutes since results are returned.
Instructions to send the request using the software POSTMAN are as follows:
Body
Example for returned result of cropped image and identity photo:
The original image
The cropped image of the Vietnamese ID card
The face photo