Skip to content

Commit

Permalink
Merge pull request #215 from zhanghuiyao/master
Browse files Browse the repository at this point in the history
fix data.utils.segment2box bug
  • Loading branch information
zhanghuiyao authored Sep 26, 2023
2 parents 23ac8ab + a7a1bee commit f8bd518
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mindyolo/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,13 @@ def segments2boxes(segments):
return xyxy2xywh(np.array(boxes)) # cls, xywh


def segment2box(segment):
def segment2box(segment, width=640, height=640):
# Convert 1 segment label to 1 box label, applying inside-image constraint, i.e. (xy1, xy2, ...) to (xyxy)
x, y = segment.T # segment xy
return np.array([x.min(), y.min(), x.max(), y.max()]) if any(x) else np.zeros(4) # xyxy
inside = (x >= 0) & (y >= 0) & (x <= width) & (y <= height)
x, y = x[inside], y[inside]
return np.array([x.min(), y.min(), x.max(), y.max()], dtype=segment.dtype) \
if any(x) else np.zeros(4, dtype=segment.dtype) # xyxy


def box_candidates(box1, box2, wh_thr=2, ar_thr=20, area_thr=0.1, eps=1e-16): # box1(4,n), box2(4,n)
Expand Down

0 comments on commit f8bd518

Please sign in to comment.