MCPcopy Create free account
hub / github.com/VitoHowe/glm-coding / bbox_iou

Function bbox_iou

app/services/tenvision_adapter.py:107–121  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

105
106 ix1 = max(ax, bx)
107 iy1 = max(ay, by)
108 ix2 = min(ax2, bx2)
109 iy2 = min(ay2, by2)
110 if ix2 <= ix1 or iy2 <= iy1:
111 return 0.0
112 inter = (ix2 - ix1) * (iy2 - iy1)
113 union = aw * ah + bw * bh - inter
114 return float(inter / union) if union > 0 else 0.0
115
116
117def crop_bbox(img, bbox, pad=2):
118 x, y, w, h = bbox
119 x1 = max(0, x - pad)
120 y1 = max(0, y - pad)
121 x2 = min(img.shape[1], x + w + pad)
122 y2 = min(img.shape[0], y + h + pad)
123 return img[y1:y2, x1:x2].copy(), (x1, y1, x2, y2)
124

Callers 1

is_ignored_itemFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected