5
5
from PIL import Image
6
6
7
7
from surya .common .util import clean_boxes
8
- from surya .detection .affinity import get_vertical_lines
9
8
from surya .detection import TextDetectionResult
10
9
from surya .common .polygon import PolygonBox
11
10
from surya .settings import settings
@@ -62,7 +61,11 @@ def detect_boxes(linemap, text_threshold, low_text):
62
61
ex , ey = min (img_w , x + w + niter + buffer ), min (img_h , y + h + niter + buffer )
63
62
64
63
mask = labels [sy :ey , sx :ex ] == k
65
- line_max = np .max (linemap [sy :ey , sx :ex ][mask ])
64
+ selected_linemap = linemap [sy :ey , sx :ex ][mask ]
65
+ if selected_linemap .size == 0 :
66
+ continue
67
+
68
+ line_max = np .max (selected_linemap )
66
69
67
70
# thresholding
68
71
if line_max < text_threshold :
@@ -136,27 +139,6 @@ def get_and_clean_boxes(
136
139
return bboxes
137
140
138
141
139
- def parallel_get_lines (preds , orig_sizes , include_maps = False ):
140
- heatmap , affinity_map = preds
141
- heat_img , aff_img = None , None
142
- if include_maps :
143
- heat_img = Image .fromarray ((heatmap * 255 ).astype (np .uint8 ))
144
- aff_img = Image .fromarray ((affinity_map * 255 ).astype (np .uint8 ))
145
- affinity_size = list (reversed (affinity_map .shape ))
146
- heatmap_size = list (reversed (heatmap .shape ))
147
- bboxes = get_and_clean_boxes (heatmap , heatmap_size , orig_sizes )
148
- vertical_lines = get_vertical_lines (affinity_map , affinity_size , orig_sizes )
149
-
150
- result = TextDetectionResult (
151
- bboxes = bboxes ,
152
- vertical_lines = vertical_lines ,
153
- heatmap = heat_img ,
154
- affinity_map = aff_img ,
155
- image_bbox = [0 , 0 , orig_sizes [0 ], orig_sizes [1 ]],
156
- )
157
- return result
158
-
159
-
160
142
def parallel_get_boxes (preds , orig_sizes , include_maps = False ):
161
143
heatmap , affinity_map = preds
162
144
heat_img , aff_img = None , None
@@ -176,7 +158,6 @@ def parallel_get_boxes(preds, orig_sizes, include_maps=False):
176
158
177
159
result = TextDetectionResult (
178
160
bboxes = bboxes ,
179
- vertical_lines = [],
180
161
heatmap = heat_img ,
181
162
affinity_map = aff_img ,
182
163
image_bbox = [0 , 0 , orig_sizes [0 ], orig_sizes [1 ]],
0 commit comments