File size: 1,171 Bytes
1f72938
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)