Spaces:
Build error
Build error
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() |