Update utils.py
Browse files
utils.py
CHANGED
@@ -377,23 +377,10 @@ def get_text_to_panel_mapping(text_bboxes, sorted_panel_bboxes):
|
|
377 |
return text_to_panel_mapping
|
378 |
|
379 |
def sort_texts_within_panel(rects):
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
smallest_y = min(smallest_y, y1)
|
385 |
-
greatest_x = max(greatest_x, x2)
|
386 |
-
|
387 |
-
reference_point = Point(greatest_x, smallest_y)
|
388 |
-
|
389 |
-
polygons_and_index = []
|
390 |
-
for i, rect in enumerate(rects):
|
391 |
-
x1, y1, x2, y2 = rect
|
392 |
-
polygons_and_index.append((box(x1,y1,x2,y2), i))
|
393 |
-
# sort points by closest to reference point
|
394 |
-
polygons_and_index = sorted(polygons_and_index, key=lambda x: reference_point.distance(x[0]))
|
395 |
-
indices = [x[1] for x in polygons_and_index]
|
396 |
-
return indices
|
397 |
|
398 |
def x1y1wh_to_x1y1x2y2(bbox):
|
399 |
x1, y1, w, h = bbox
|
|
|
377 |
return text_to_panel_mapping
|
378 |
|
379 |
def sort_texts_within_panel(rects):
|
380 |
+
# Sort primarily by Y-coordinate (top-to-bottom), then X-coordinate (left-to-right)
|
381 |
+
sorted_indices = sorted(range(len(rects)), key=lambda i: (rects[i][1], rects[i][0]))
|
382 |
+
return sorted_indices
|
383 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
384 |
|
385 |
def x1y1wh_to_x1y1x2y2(bbox):
|
386 |
x1, y1, w, h = bbox
|