-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
131 lines (100 loc) · 4.86 KB
/
main.py
File metadata and controls
131 lines (100 loc) · 4.86 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import tb.OcrToTableTool as ottt
import tb.TableExtractor as te
import tb.TableLinesRemover as tlr
import tb.ReadTable as rt
import src.config.IocConfig
from src.config.IocContainer import AppContext
from src.config.ContextType import ( RepositoryType, ServiceType )
from src.config.database_util import DatabaseUtil
import cv2
path_to_image = "./figure/0.jpg"
def Table_ex(table_name, table):
table_extractor = te.TableExtractor(table)
perspective_corrected_image = table_extractor.execute()
gray = cv2.cvtColor(perspective_corrected_image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5,5,), 0)
edged = cv2.Canny(blurred, 75, 200)
cv2.imwrite(f'./tmp_figure/{table_name}.jpg', perspective_corrected_image)
return perspective_corrected_image
def db_USER_STATUS_SERVICE(data):
userService = AppContext.get(ServiceType.USER_STATUS_SERVICE)
userService.saveByDictionary(data)
def db_WORK_TIME_SERVICE(data):
userService = AppContext.get(ServiceType.WORK_TIME_SERVICE)
userService.saveByDictionary(data)
def db_OPERATION_SERVICE(data):
userService = AppContext.get(ServiceType.OPERATION_RATE_SERVICE)
userService.saveByDictionary(data)
def db_PRODUCTION_SERVICE(data):
userService = AppContext.get(ServiceType.PRODUCTION_RATE_SERVICE)
userService.saveByDictionary(data)
def db_PRODUCTION_CONTEXT_SERVICE(data):
userService = AppContext.get(ServiceType.PRODUCTION_CONTEXT_SERVICE)
userService.saveByDictionary(data)
def db_ERROR_CONTEXT_SERVICE(data):
userService = AppContext.get(ServiceType.ERROR_CONTEXT_SERVICE)
userService.saveByDictionary(data)
def db_SALE_CONTEXT_SERVICE(data):
userService = AppContext.get(ServiceType.SALE_CONTEXT_SERVICE)
userService.saveByDictionary(data)
def printData() :
userService = AppContext.get(ServiceType.USER_STATUS_SERVICE)
userService.printDataAll()
print('*'*20)
userService = AppContext.get(ServiceType.WORK_TIME_SERVICE)
userService.printDataAll()
print('*'*20)
userService = AppContext.get(ServiceType.OPERATION_RATE_SERVICE)
userService.printDataAll()
print('*'*20)
userService = AppContext.get(ServiceType.PRODUCTION_RATE_SERVICE)
userService.printDataAll()
print('*'*20)
userService = AppContext.get(ServiceType.PRODUCTION_CONTEXT_SERVICE)
userService.printDataAll()
print('*'*20)
userService = AppContext.get(ServiceType.ERROR_CONTEXT_SERVICE)
userService.printDataAll()
print('*'*20)
userService = AppContext.get(ServiceType.SALE_CONTEXT_SERVICE)
userService.printDataAll()
def update_value(dict):
for key, value in dict.items():
if len(value) == 0:
dict[key] = 'None'
else:
dict[key] = value[0]
return dict
if __name__=='__main__':
## 이미지에서 테이블 분리
dict_table = rt.ReadDailyTable(path_to_image).execute()
## 분리된 테이블에서 테이블만 저장
img_dict = {}
for keys in dict_table:
# print(keys)
img = Table_ex(keys, dict_table[keys])
img_dict[keys] = img
ocr = rt.setting_ocr()
result_UserStatus = ocr.ocr_UserStatus(img_dict['user_statuses'])
result_WorkTime_unit_1, result_WorkTime_unit_2 = ocr.ocr_WorkTime(img_dict['work_time'])
result_operation_unit_1, result_operation_unit_2, result_production_unit_1, result_production_unit_2 = ocr.ocr_WorkYeild(img_dict['work_yeild'])
result_ProductionContext_unit_1, result_ProductionContext_unit_2 = ocr.ocr_ProductionContext(img_dict['production_context'])
result_ErrorContext_unit_1, result_ErrorContext_unit_2 = ocr.ocr_ErrorContext(img_dict['error_context'])
result_SaleContext_11,result_SaleContext_12, result_SaleContext_21, result_SaleContext_22 = ocr.ocr_SaleContext(img_dict['sale_context'])
DatabaseUtil.clear_all_data()
db_USER_STATUS_SERVICE(update_value(result_UserStatus))
db_WORK_TIME_SERVICE(update_value(result_WorkTime_unit_1))
db_WORK_TIME_SERVICE(update_value(result_WorkTime_unit_2))
db_OPERATION_SERVICE(update_value(result_operation_unit_1))
db_OPERATION_SERVICE(update_value(result_operation_unit_2))
db_PRODUCTION_SERVICE(update_value(result_production_unit_1))
db_PRODUCTION_SERVICE(update_value(result_production_unit_2))
db_PRODUCTION_CONTEXT_SERVICE(update_value(result_ProductionContext_unit_1))
db_PRODUCTION_CONTEXT_SERVICE(update_value(result_ProductionContext_unit_2))
db_ERROR_CONTEXT_SERVICE(update_value(result_ErrorContext_unit_1))
db_ERROR_CONTEXT_SERVICE(update_value(result_ErrorContext_unit_2))
db_SALE_CONTEXT_SERVICE(update_value(result_SaleContext_11))
db_SALE_CONTEXT_SERVICE(update_value(result_SaleContext_12))
db_SALE_CONTEXT_SERVICE(update_value(result_SaleContext_21))
db_SALE_CONTEXT_SERVICE(update_value(result_SaleContext_22))
printData()