File size: 2,350 Bytes
7bbae49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from constants.paths import IMAGE_PATH
from extract_country.country_extract import country_extractor
from extract_dates.date_engine import date_extractor
from extract_gender.gender_extractor import gender_extract
from extract_identity_number.identity_number import identity_card_extractor
from extract_mrz.mrz_detect import MRZ_detector
from ocr_engine.ocr import ocr
from extract_mrz import mrz_engine
import re

def main():
    global extract_text
    extract_text = []

    mrz_found, cropped = MRZ_detector(IMAGE_PATH)

    result = ocr.ocr(cropped, cls=True) #extracting MRZ text with ocr

    if mrz_found and not (len(result) <= 1):
        
        lenghtOfCharaters = 0
        capital_strings = []
        print('\n')
        for x,line in enumerate(result[0]):
            text = line[1][0]
            
            print(text)

            capital_strings.append(text.upper())
            lenghtOfCharaters = len(text.upper()) + lenghtOfCharaters
        
        print('\n')
        print("Extracted Text : ",capital_strings)
        print("The lenght of charaters is : ", lenghtOfCharaters)

        lenghtOfCharaters, capital_strings = mrz_engine.mrz_corrector(capital_strings,lenghtOfCharaters)

        if lenghtOfCharaters != 0 and len(capital_strings) != 0:
            user_data = mrz_engine(capital_strings,lenghtOfCharaters)
            print("USER DATA : ", user_data)
    else:
        print("MRZ NOT FOUND \nExtracting full card \n")
        
        result = ocr.ocr(IMAGE_PATH, cls=True)
        print("\n")

        # extract_text = [] #storing extracting text in a list

        for idx in range(len(result)):
            res = result[idx]
            for line in res:
                string_value = line[1][0]
                extract_text.append(string_value)
                
        print("LIST : ", extract_text)
        
        dob_found, dob, ocr_list = date_extractor(extract_text)
        # gender_found, gender, ocr_list = gender_extract(ocr_list)
        # country_found, country, ocr_list = country_extractor(ocr_list)
        # identity_number_found, identity_number, ocr_list = identity_card_extractor(ocr_list)
        # dob_found, DOB = date_extractor(extract_text)
        # dob_found, DOB = date_extractor(extract_text)
        # print("UPDAETD LIST : ", ocr_list)

if __name__ == "__main__":
    main()