SWHL commited on
Commit
86e03fd
1 Parent(s): 0c54c5e

Upload 11 files

Browse files
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ images/layout/layout1.png filter=lfs diff=lfs merge=lfs -text
app.py CHANGED
@@ -10,12 +10,84 @@ from PIL import Image
10
  from rapid_layout import RapidLayout
11
  from rapid_orientation import RapidOrientation
12
  from rapid_table import RapidTable
 
13
 
14
  orientation_engine = RapidOrientation()
15
  layout_engine = RapidLayout()
16
  table_engine = RapidTable()
17
 
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def vis_layout(img: np.ndarray, layout_res: list) -> None:
20
  tmp_img = copy.deepcopy(img)
21
  for v in layout_res:
@@ -25,12 +97,47 @@ def vis_layout(img: np.ndarray, layout_res: list) -> None:
25
  start_point = (bbox[0], bbox[1])
26
  end_point = (bbox[2], bbox[3])
27
 
28
- cv2.rectangle(tmp_img, start_point, end_point, (0, 255, 0), 2)
29
  cv2.putText(tmp_img, label, start_point,
30
- cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 255), 2)
31
  return tmp_img
32
 
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  def vis_table(table_res) -> str:
35
  style_res = '''<style>td {border-left: 1px solid;border-bottom:1px solid;}
36
  table, th {border-top:1px solid;font-size: 10px;
@@ -55,55 +162,6 @@ if __name__ == '__main__':
55
 
56
  img_suffix = ["png", "jpg", "jpeg"]
57
 
58
- st.markdown('##### [文档图像方向分类](https://github.com/RapidAI/RapidStructure/blob/main/docs/README_Orientation.md)')
59
-
60
- img_file_buffer = st.file_uploader("Upload an image", type=img_suffix,
61
- key='orientation',
62
- label_visibility='collapsed')
63
- col1, col2 = st.columns([5, 5])
64
-
65
- img_empty = col1.empty()
66
- if img_file_buffer:
67
- image = Image.open(img_file_buffer)
68
- img = np.array(image)
69
- img_empty.image(image, use_column_width=True)
70
-
71
- img_array = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
72
- orientation_res, elapse = orientation_engine(img)
73
-
74
- col2.markdown(f'- 方向分类结果:{orientation_res}° \n - 耗费时间:{elapse:.4f}s')
75
-
76
- st.markdown('##### [文档图像版面分析](https://github.com/RapidAI/RapidStructure/blob/main/docs/README_Layout.md)')
77
- img_file_buffer = st.file_uploader("Upload an image", type=img_suffix,
78
- key='layout',
79
- label_visibility='collapsed')
80
- layout_col1, layout_col2 = st.columns([5, 5])
81
-
82
- img_empty = layout_col1.empty()
83
- if img_file_buffer:
84
- image = Image.open(img_file_buffer)
85
- img = np.array(image)
86
- img_empty.image(image, use_column_width=True)
87
-
88
- img_array = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
89
- layout_res, _ = layout_engine(img)
90
- drawed_img = vis_layout(img, layout_res)
91
- layout_col2.image(drawed_img, use_column_width=True)
92
-
93
- st.markdown('##### [表格还原](https://github.com/RapidAI/RapidStructure/blob/main/docs/README_Table.md)')
94
- img_file_buffer = st.file_uploader("Upload an image", type=img_suffix,
95
- key='table',
96
- label_visibility='collapsed')
97
- table_col1, table_col2 = st.columns([5, 5])
98
-
99
- img_empty = table_col1.empty()
100
- if img_file_buffer:
101
- image = Image.open(img_file_buffer)
102
- img = np.array(image)
103
- img_empty.image(image, use_column_width=True)
104
-
105
- img_array = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
106
- table_html_str, _ = table_engine(img)
107
-
108
- table_html_str = vis_table(table_html_str)
109
- table_col2.markdown(table_html_str, unsafe_allow_html=True)
 
10
  from rapid_layout import RapidLayout
11
  from rapid_orientation import RapidOrientation
12
  from rapid_table import RapidTable
13
+ from streamlit_image_select import image_select
14
 
15
  orientation_engine = RapidOrientation()
16
  layout_engine = RapidLayout()
17
  table_engine = RapidTable()
18
 
19
 
20
+ def orientation_part():
21
+ st.markdown('##### 文档图像方向分类')
22
+ img = image_select(
23
+ label="示例图(点击选择)",
24
+ images=[
25
+ 'images/orientation/img_rot0_demo.jpg',
26
+ 'images/orientation/rot_90.jpg',
27
+ 'images/orientation/img_rot180_demo.jpg',
28
+ 'images/orientation/rot_270.jpg'
29
+ ],
30
+ captions=['0', '90', '180', '270'],
31
+ key='cls'
32
+ )
33
+ img_file_buffer = st.file_uploader("Upload an image", type=img_suffix,
34
+ key='orientation',
35
+ label_visibility='collapsed')
36
+
37
+ col1, col2 = st.columns([5, 5])
38
+ img_empty = col1.empty()
39
+
40
+ image, orientation_res, elapse = get_cls_res(img)
41
+ if img_file_buffer:
42
+ image, orientation_res, elapse = get_cls_res(img_file_buffer)
43
+
44
+ img_empty.image(image, use_column_width=True)
45
+ col2.markdown(f'- 方向分类结果:{orientation_res}° \n - 耗费时间:{elapse:.4f}s')
46
+
47
+
48
+ def get_cls_res(img_file_buffer):
49
+ image = Image.open(img_file_buffer)
50
+ img = np.array(image)
51
+ img_array = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
52
+ orientation_res, elapse = orientation_engine(img_array)
53
+ return image, orientation_res, elapse
54
+
55
+
56
+ def layout_part():
57
+ st.markdown('##### 文档图像版面分析')
58
+ img = image_select(
59
+ label="示例图(点击选择)",
60
+ images=[
61
+ 'images/layout/layout.png',
62
+ 'images/layout/layout1.png',
63
+ 'images/layout/layout2.png',
64
+ ],
65
+ key='layout_select'
66
+ )
67
+ img_file_buffer = st.file_uploader("Upload an image", type=img_suffix,
68
+ key='layout',
69
+ label_visibility='collapsed')
70
+
71
+ layout_col1, layout_col2 = st.columns([5, 5])
72
+ img_empty = layout_col1.empty()
73
+
74
+ image, drawed_img = get_layout_res(img)
75
+ if img_file_buffer:
76
+ image, drawed_img = get_layout_res(img_file_buffer)
77
+
78
+ img_empty.image(image, use_column_width=True)
79
+ layout_col2.image(drawed_img, use_column_width=True)
80
+
81
+
82
+ def get_layout_res(img_file_buffer):
83
+ image = Image.open(img_file_buffer)
84
+ img = np.array(image)
85
+ img_array = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
86
+ layout_res, _ = layout_engine(img_array)
87
+ drawed_img = vis_layout(img, layout_res)
88
+ return image, drawed_img
89
+
90
+
91
  def vis_layout(img: np.ndarray, layout_res: list) -> None:
92
  tmp_img = copy.deepcopy(img)
93
  for v in layout_res:
 
97
  start_point = (bbox[0], bbox[1])
98
  end_point = (bbox[2], bbox[3])
99
 
100
+ cv2.rectangle(tmp_img, start_point, end_point, (0, 0, 0), 2)
101
  cv2.putText(tmp_img, label, start_point,
102
+ cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 0), 2)
103
  return tmp_img
104
 
105
 
106
+ def table_part():
107
+ st.markdown('##### 表格还原')
108
+ img = image_select(
109
+ label="示例图(点击选择)",
110
+ images=[
111
+ 'images/table/table.jpg',
112
+ 'images/table/table1.png',
113
+ 'images/table/table2.png',
114
+ ],
115
+ key='table_select'
116
+ )
117
+ img_file_buffer = st.file_uploader("Upload an image", type=img_suffix,
118
+ key='table',
119
+ label_visibility='collapsed')
120
+
121
+ table_col1, table_col2 = st.columns([5, 5])
122
+ img_empty = table_col1.empty()
123
+
124
+ image, table_html_str = get_table_res(img)
125
+ if img_file_buffer:
126
+ image, table_html_str = get_table_res(img_file_buffer)
127
+
128
+ img_empty.image(image, use_column_width=True)
129
+ table_col2.markdown(table_html_str, unsafe_allow_html=True)
130
+
131
+
132
+ def get_table_res(img_file_buffer):
133
+ image = Image.open(img_file_buffer)
134
+ img = np.array(image)
135
+ img_array = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
136
+ table_html_str, _ = table_engine(img_array)
137
+ table_html_str = vis_table(table_html_str)
138
+ return image, table_html_str
139
+
140
+
141
  def vis_table(table_res) -> str:
142
  style_res = '''<style>td {border-left: 1px solid;border-bottom:1px solid;}
143
  table, th {border-top:1px solid;font-size: 10px;
 
162
 
163
  img_suffix = ["png", "jpg", "jpeg"]
164
 
165
+ orientation_part()
166
+ layout_part()
167
+ table_part()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
images/layout/layout.png ADDED
images/layout/layout1.png ADDED

Git LFS Details

  • SHA256: 9193b9ecbac6d8cd54180e9f7217490e5564f4af6f75a88f620648ca33f0f906
  • Pointer size: 132 Bytes
  • Size of remote file: 1.65 MB
images/layout/layout2.png ADDED
images/orientation/img_rot0_demo.jpg ADDED
images/orientation/img_rot180_demo.jpg ADDED
images/orientation/rot_270.jpg ADDED
images/orientation/rot_90.jpg ADDED
images/table/table.jpg ADDED
images/table/table1.png ADDED
images/table/table2.png ADDED