|
- import os
- import numpy as np
- import matplotlib.pyplot as plt
-
- import bin.caracter_recognition as cocr
- import bin.signal_processing as ts
- import bin.form_data_places as form
-
- class FileNames:
- template_object_name = "/template"
- template_image_name = "/template_img.png"
- template_extension = ".opdf"
- general_path = os.path.abspath(os.path.dirname(__file__))
- scanned_path = general_path + "/scanned"
- templates_path = general_path + "/templates"
- ocr_model_path = general_path + "/OCR_model"
-
- fn_model_path = general_path + "/OCR_model"
- fn_dump_path = general_path + "/dump"
- fn_char_list = general_path + "/OCR_model/charList.txt"
- fn_summary = general_path + "/OCR_model/summary.json"
- fn_corpus = general_path + "/data/corpus.txt"
-
-
-
- def image_scanned_processing(scanned_img_path, template_path):
- template_object_path = template_path + FileNames.template_object_name + FileNames.template_extension
- template_img_path = template_path + FileNames.template_image_name
-
- template_object = form.Template_File()
- template_object.open_files(template_img_path, template_object_path)
-
- scanned_img = plt.imread(scanned_img_path)
- scanned_img = (scanned_img[:,:,0]+scanned_img[:,:,1]+scanned_img[:,:,2])*255//3
-
- img_template_resized, img_scanned_trunc, ratio, offset = ts.signal_processing_process(template_object.template_img, scanned_img)
-
- handwritten = form.Handwritten_Content(FileNames)
- handwritten.extract_handwritten_content(template_object, img_template_resized, img_scanned_trunc, ratio, offset)
- return handwritten
-
- def menu():
- print(" OCR_paper_form 0.1 terminal\nCree par Lilian RM pour la Gemme\n License MIT\n")
- answer = int(input(" 1. Scanner formulaires\n 2. Creer modele\n 3. Modifier modele\n 4. Quitter\n->"))
- while(answer != 4):
- if(answer == 1):
- template_list = os.listdir(FileNames.templates_path)
- for i in range(0,len(template_list)):
- print(i+1, template_list[i])
- template_choice = int(input("Modele a utiliser : "))
- template_path = FileNames.templates_path+"/"+template_list[template_choice-1]
- # template_object = Template_File()
- # template_files = os.listdir(template_path)
- # if(FileNames.template_extension in template_files[0]):
- # template_object.open_files(template_path+"/"+template_files[1], template_path+"/"+template_files[0])
- # else:
- # template_object.open_files(template_path+"/"+template_files[0], template_path+"/"+template_files[1])
-
- print("Merci de verifier que tous les fichiers scannes sont:\n- en format PNG\n- dans le dossier interne \"scanned\" du logiciel\nSinon définissez le chemin complet a utiliser, ou appuyez sur Entree")
- path = str(input("->"))
- if(path != ""):
- FileNames.scanned_path = path
- file_list = os.listdir(FileNames.scanned_path)
- handwritten = []
- for img_file in file_list:
- handwritten.append(image_scanned_processing(FileNames.scanned_path + "/" + img_file, template_path))
- if(answer == 2):
- template_object = form.Template_File()
- template_object.define_template_img()
- add = "O"
- while(add != "N"):
- template_object.add_template_information()
- add = str(input("Ajouter une information? O/N : "))
- template_object.show_template_boxes()
- template_object.save_template(FileNames.templates_path + "/" + template_object.template_name, FileNames.template_image_name, FileNames.template_object_name, FileNames.template_extension)
- # if(answer == 3):
- # template_list = os.listdir(FileNames.templates_path)
- # for i in range(0,len(template_list)):
- # print(i+1, template_list[i])
- # template_choice = int(input("Modele a modifier : "))
- # template_path = FileNames.templates_path+"/"+template_list[template_choice-1]
-
- answer = int(input("\n 1. Scanner formulaires\n 2. Creer modele\n 3. Modifier modele\n 4. Quitter\n->"))
-
- print("Execution success")
-
-
-
-
-
- if __name__ == "__main__":
- menu()
|