You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
4.2KB

  1. import os
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. import bin.caracter_recognition as cocr
  5. import bin.signal_processing as ts
  6. import bin.form_data_places as form
  7. class FileNames:
  8. template_object_name = "/template"
  9. template_image_name = "/template_img.png"
  10. template_extension = ".opdf"
  11. general_path = os.path.abspath(os.path.dirname(__file__))
  12. scanned_path = general_path + "/scanned"
  13. templates_path = general_path + "/templates"
  14. ocr_model_path = general_path + "/OCR_model"
  15. fn_model_path = general_path + "/OCR_model"
  16. fn_dump_path = general_path + "/dump"
  17. fn_char_list = general_path + "/OCR_model/charList.txt"
  18. fn_summary = general_path + "/OCR_model/summary.json"
  19. fn_corpus = general_path + "/data/corpus.txt"
  20. def image_scanned_processing(scanned_img_path, template_path):
  21. template_object_path = template_path + FileNames.template_object_name + FileNames.template_extension
  22. template_img_path = template_path + FileNames.template_image_name
  23. template_object = form.Template_File()
  24. template_object.open_files(template_img_path, template_object_path)
  25. scanned_img = plt.imread(scanned_img_path)
  26. scanned_img = (scanned_img[:,:,0]+scanned_img[:,:,1]+scanned_img[:,:,2])*255//3
  27. img_template_resized, img_scanned_trunc, ratio, offset = ts.signal_processing_process(template_object.template_img, scanned_img)
  28. handwritten = form.Handwritten_Content(FileNames)
  29. handwritten.extract_handwritten_content(template_object, img_template_resized, img_scanned_trunc, ratio, offset)
  30. return handwritten
  31. def menu():
  32. print(" OCR_paper_form 0.1 terminal\nCree par Lilian RM pour la Gemme\n License MIT\n")
  33. answer = int(input(" 1. Scanner formulaires\n 2. Creer modele\n 3. Modifier modele\n 4. Quitter\n->"))
  34. while(answer != 4):
  35. if(answer == 1):
  36. template_list = os.listdir(FileNames.templates_path)
  37. for i in range(0,len(template_list)):
  38. print(i+1, template_list[i])
  39. template_choice = int(input("Modele a utiliser : "))
  40. template_path = FileNames.templates_path+"/"+template_list[template_choice-1]
  41. # template_object = Template_File()
  42. # template_files = os.listdir(template_path)
  43. # if(FileNames.template_extension in template_files[0]):
  44. # template_object.open_files(template_path+"/"+template_files[1], template_path+"/"+template_files[0])
  45. # else:
  46. # template_object.open_files(template_path+"/"+template_files[0], template_path+"/"+template_files[1])
  47. 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")
  48. path = str(input("->"))
  49. if(path != ""):
  50. FileNames.scanned_path = path
  51. file_list = os.listdir(FileNames.scanned_path)
  52. handwritten = []
  53. for img_file in file_list:
  54. handwritten.append(image_scanned_processing(FileNames.scanned_path + "/" + img_file, template_path))
  55. if(answer == 2):
  56. template_object = form.Template_File()
  57. template_object.define_template_img()
  58. add = "O"
  59. while(add != "N"):
  60. template_object.add_template_information()
  61. add = str(input("Ajouter une information? O/N : "))
  62. template_object.show_template_boxes()
  63. template_object.save_template(FileNames.templates_path + "/" + template_object.template_name, FileNames.template_image_name, FileNames.template_object_name, FileNames.template_extension)
  64. # if(answer == 3):
  65. # template_list = os.listdir(FileNames.templates_path)
  66. # for i in range(0,len(template_list)):
  67. # print(i+1, template_list[i])
  68. # template_choice = int(input("Modele a modifier : "))
  69. # template_path = FileNames.templates_path+"/"+template_list[template_choice-1]
  70. answer = int(input("\n 1. Scanner formulaires\n 2. Creer modele\n 3. Modifier modele\n 4. Quitter\n->"))
  71. print("Execution success")
  72. if __name__ == "__main__":
  73. menu()