hf-similarity-check / model2.py
Mitul Mohammad Abdullah Al Mukit
first commit
1f72938
from cnocr import CnOcr
import pandas as pd
import checkTool
# img_fp = 'IMG_4499.jpg'
def model2(path):
ocr = CnOcr(rec_model_name='densenet_lite_136-gru')
# ocr = CnOcr(rec_model_name='densenet_lite_136-fc')
out = ocr.ocr(path)
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 checkTool.is_comma_present(text):
text = text.replace(',', '')
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 = model2('IMG_4496.jpg')
# print(info)
# checkTool.print_info(*info)