Skip to content

Commit b958491

Browse files
authored
Merge pull request #395 from datalab-to/vik_dev
Fix aff map
2 parents cea6250 + 419d7de commit b958491

File tree

3 files changed

+5
-188
lines changed

3 files changed

+5
-188
lines changed

surya/detection/affinity.py

Lines changed: 0 additions & 159 deletions
This file was deleted.

surya/detection/heatmap.py

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from PIL import Image
66

77
from surya.common.util import clean_boxes
8-
from surya.detection.affinity import get_vertical_lines
98
from surya.detection import TextDetectionResult
109
from surya.common.polygon import PolygonBox
1110
from surya.settings import settings
@@ -62,7 +61,11 @@ def detect_boxes(linemap, text_threshold, low_text):
6261
ex, ey = min(img_w, x + w + niter + buffer), min(img_h, y + h + niter + buffer)
6362

6463
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)
6669

6770
# thresholding
6871
if line_max < text_threshold:
@@ -136,27 +139,6 @@ def get_and_clean_boxes(
136139
return bboxes
137140

138141

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-
160142
def parallel_get_boxes(preds, orig_sizes, include_maps=False):
161143
heatmap, affinity_map = preds
162144
heat_img, aff_img = None, None
@@ -176,7 +158,6 @@ def parallel_get_boxes(preds, orig_sizes, include_maps=False):
176158

177159
result = TextDetectionResult(
178160
bboxes=bboxes,
179-
vertical_lines=[],
180161
heatmap=heat_img,
181162
affinity_map=aff_img,
182163
image_bbox=[0, 0, orig_sizes[0], orig_sizes[1]],

surya/detection/schema.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@
55
from surya.common.polygon import PolygonBox
66

77

8-
class ColumnLine(PolygonBox):
9-
vertical: bool
10-
horizontal: bool
11-
128
class TextDetectionResult(BaseModel):
139
bboxes: List[PolygonBox]
14-
vertical_lines: List[ColumnLine]
1510
heatmap: Optional[Any]
1611
affinity_map: Optional[Any]
1712
image_bbox: List[float]

0 commit comments

Comments
 (0)