hf-similarity-check / model1.py
Mitul Mohammad Abdullah Al Mukit
first commit
1f72938
from cnocr import CnOcr
import pandas as pd
import checkTool
def model1(path):
ocr = CnOcr(rec_model_name='en_PP-OCRv3')
# ocr = CnOcr(rec_model_name='densenet_lite_136-fc')
out = ocr.ocr(path)
#print(out)
name = ''
scanned_number = len(out)
hkid = out[scanned_number-1]['text']
issuedate = ''
for data in out:
text = data['text']
score = data['score']
position = data['position']
if not checkTool.check_integer(text):
if checkTool.check_alpha(text) and checkTool.is_chinese_name(text):
name = checkTool.seperate_name(text)
# check if the data is issuedate
if checkTool.check_issuedate(text):
issuedate = checkTool.format_issuedate(text)
if checkTool.validate_hkid(hkid=hkid):
valid_hkid = 'True'
hkid = checkTool.format_HKID(out[scanned_number-1]['text'])
else:
valid_hkid = 'False'
# checkTool.print_info(name, hkid, valid_hkid, issuedate)
return [name, valid_hkid, hkid, issuedate]
# example for testing
# info = model1('IMG_4495.jpg')
# print(info)
# checkTool.print_info(*info)