Files
wehub-resource-sync 925e56bb5f
Unit tests / build (t4_gpu) (push) Has been cancelled
Unit tests / build (ubuntu-latest) (push) Has been cancelled
Unit tests / build (windows-latest) (push) Has been cancelled
Test CLI scripts / build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:24:56 +08:00

45 lines
1.2 KiB
Python

from typing import List
from surya.common.polygon import PolygonBox
def clean_boxes(boxes: List[PolygonBox]) -> List[PolygonBox]:
new_boxes = []
for box_obj in boxes:
xs = [point[0] for point in box_obj.polygon]
ys = [point[1] for point in box_obj.polygon]
if max(xs) == min(xs) or max(ys) == min(ys):
continue
box = box_obj.bbox
contained = False
for other_box_obj in boxes:
if other_box_obj.polygon == box_obj.polygon:
continue
other_box = other_box_obj.bbox
if box == other_box:
continue
if (
box[0] >= other_box[0]
and box[1] >= other_box[1]
and box[2] <= other_box[2]
and box[3] <= other_box[3]
):
contained = True
break
if not contained:
new_boxes.append(box_obj)
return new_boxes
def expand_bbox(bbox, expansion_factor=0.01):
expansion_low = 1 - expansion_factor
expansion_high = 1 + expansion_factor
return [
bbox[0] * expansion_low,
bbox[1] * expansion_low,
bbox[2] * expansion_high,
bbox[3] * expansion_high,
]