Library for extract infomation from thai personal identity card
Project description
ThaiPersonalCardExtract
Library for extract infomation from thai personal identity card. imprement from easyocr and tesseract
New Feature v1.3.1 🎁
- Increase performance.
- Support Thai Driving License (Beta) สามารถสกัดข้อมูลจากภาพถ่ายใบขับขี่ได้บางรูปแบบ เนื่องจาก กรมทางขนส่งทางบก มีรูปแบบบัตรหลากหลายรูปแบบ และแต่ละรูปแบบมีตำแหน่งข้อมูลที่แตกต่างกัน จึงทำให้ประสิทธิภาพต่ำ
- Support Thai Government Lottery (16 Aug. 2021)
Examples
Real image file.
wrapPerpective image crop.
keypoint of image detected.
Resutls of library extract region of interest
|
|
---|---|
|
|
|
|
|
|
|
|
|
|
Recommend ⚠
- Image quality lowest should be 600x350
- Images with minimal reflections should be used. for good results
- Identity Card should be size in the image about 75%, if the image doesn't cropped that to be left only Identity Card area.
- For faster, please resize image and usage CUDA GPU.
Installation
Install using pip
for stable release,
pip install thai-personal-card-extract
For latest development release,
pip install git+git://github.com/ggafiled/ThaiPersonalCardExtrac.git
Note 1: for Windows, please install tesseract first by following the official instruction here https://medium.com/@navapat.tpb/734dae2fb4d3 On medium website, be sure to setup already.
Note 2: for Linux os, please install tesseract by following the official instruction https://github.com/tesseract-ocr/tesseract
Usage
# With build-in Config Options.
import ThaiPersonalCardExtract as card
reader = card.PersonalCard(
lang=card.THAI,
provider=card.DEFAULT,
tesseract_cmd="D:/Program Files/Tesseract-OCR/tesseract",
save_extract_result=True,
path_to_save="D:/dev/ThaiPersonalCardExtract/examples/extract")
result = reader.extractInfo('examples/card.jpg')
print(result)
# With free-style
from ThaiPersonalCardExtract import PersonalCard
reader = PersonalCard(lang="mix", tesseract_cmd="D:/Program Files/Tesseract-OCR/tesseract") # for windows need to pass tesseract_cmd parameter to setup your tesseract command path.
result = reader.extractInfo('examples/card.jpg')
print(result)
# With free-style
from ThaiPersonalCardExtract import DrivingLicense
reader = DrivingLicense(lang="mix", tesseract_cmd="D:/Program Files/Tesseract-OCR/tesseract") # for windows need to pass tesseract_cmd parameter to setup your tesseract command path.
result = reader.extractInfo('examples/card.jpg')
print(result)
# With free-style
from ThaiPersonalCardExtract import ThaiGovernmentLottery
reader = ThaiGovernmentLottery(lang="mix", tesseract_cmd="D:/Program Files/Tesseract-OCR/tesseract") # for windows need to pass tesseract_cmd parameter to setup your tesseract command path.
result = reader.extractInfo('examples/card.jpg')
print(result)
Output will be in list format, each item represents result of library can extract, respectively.
#Output of PersonalCard
{
"Identification_Number": "9999999999999",
"FullNameTH": "นาย อายุมฺมุราเสะ",
"PrefixTH": "นาย",
"NameTH": "อายุมฺมุราเสะ",
"LastNameTH": "อายุมฺมุราเสะ",
"PrefixEN": "Me",
"NameEN": "Shoys",
"LastNameEN": "Hinata",
"BirthdayTH": "21 มี.ย. 2539",
"BirthdayEN": "21 Jun..1996",
"Religion": "พุทธ",
"Address": "ท๒ 99/1 มิชีโฮะ เขตฮานามิกาวา อำเภอชิบ;",
"DateOfIssueTH": "11 ส.ค. 2554",
"DateOfIssueEN": "~11 Ang. 2021",
"DateOfExpiryTH": "11 ส.ค. 2574",
"DateOfExpiryEN": "21 ug. 2092"
}
#Output of ThaiGovernmentLottery
{
"LotteryNumber":"424603",
"DateLesson":"16 กุมภ1พันธ์ 2564",
"LessonNumber":"",
"SetNumber":"23"
}
For set lang
attribute to tha
from ThaiPersonalCardExtract import PersonalCard
reader = PersonalCard(lang="tha", tesseract_cmd="D:/Program Files/Tesseract-OCR/tesseract") # for windows need to pass tesseract_cmd parameter to setup your tesseract command path.
result = reader.extractInfo('examples/card.jpg')
print(result)
Output will be in list format, each item represents result of library can extract, respectively.
{
"Identification_Number": "9999999999999",
"FullNameTH": "นาย อายุมฺมุราเสะ",
"PrefixTH": "นาย",
"NameTH": "อายุมฺมุราเสะ",
"LastNameTH": "อายุมฺมุราเสะ",
"BirthdayTH": "21 มี.ย. 2539",
"Religion": "พุทธ",
"Address": "ท๒ 99/1 มิชีโฮะ เขตฮานามิกาวา อำเภอชิบ;",
"DateOfIssueTH": "11 ส.ค. 2554",
"DateOfExpiryTH": "11 ส.ค. 2574"
}
And you can set ocr provider following below default #used both easyocr and tesseract **Recommend
Or easyocr
Or tesseract
from ThaiPersonalCardExtract import PersonalCard
reader = PersonalCard(lang="tha", provider="default", tesseract_cmd="D:/Program Files/Tesseract-OCR/tesseract") # for windows need to pass tesseract_cmd parameter to setup your tesseract command path.
result = reader.extractInfo('examples/card.jpg')
print(result)
Config Options
you can set options to Instance by below keyword
Parameter name | Value Type | Example |
---|---|---|
lang | String | Expected Results Language bash mix #get all area both tha and eng Or bash tha Or bash eng *Default is 'mix' |
provider | String | OCR Provider have bash default #used both easyocr and tesseract **Recommend Or bash easyocr Or bash tesseract *Default is 'default' |
template_threshold | Double | Rate to cals similarity of template *Default is 0.7 |
sift_rate | Int | Feature Keypoint rate *Default is 25,000 |
tesseract_cmd | String | Path of your tesseract command **For windows only. |
save_extract_result | Boolean | Set True if you want to save extracted image *Default is False |
path_to_save | String | Path that you given it save extracted image, relative with save_extract_result=True |
Donate Me ☕
Mr.Nattapol Krobklang
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for thai-personal-card-extract-1.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a638ddca4aaa18fa90b163bad0ddd23b480efadb14473d6e664a332db068e241 |
|
MD5 | 322568e039b7801f0cc3edd96781c465 |
|
BLAKE2b-256 | a453b62d4df5b33f02f18a1320868dfc44e81b0f94a635ea9b4ebc7f2c1ab8df |
Hashes for thai_personal_card_extract-1.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b3dd2a12a298592258c8b2ce3957d18b6404083af08989652e977197cff1868 |
|
MD5 | 24ef9e9fa9253fa54aa070ab3e6bf1e2 |
|
BLAKE2b-256 | 54ab9bc45f1cb195a44baaeb6af2ac89f0733c410a80dcc1b525356f103ed369 |