MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / IoU

Function IoU

flow-python/examples/application/utils.py:126–139  ·  view source on GitHub ↗
(rect1, rect2, iob_threshold)

Source from the content-addressed store, hash-verified

124
125
126def IoU(rect1, rect2, iob_threshold):
127 a1 = (rect1[:, 2] - rect1[:, 0] + 1) * (rect1[:, 3] - rect1[:, 1] + 1)
128 a2 = (rect2[:, 2] - rect2[:, 0] + 1) * (rect2[:, 3] - rect2[:, 1] + 1)
129 xx1 = np.maximum(rect1[:, 0], rect2[:, 0])
130 yy1 = np.maximum(rect1[:, 1], rect2[:, 1])
131 xx2 = np.minimum(rect1[:, 2], rect2[:, 2])
132 yy2 = np.minimum(rect1[:, 3], rect2[:, 3])
133 dx = np.maximum(0, xx2 - xx1 + 1)
134 dy = np.maximum(0, yy2 - yy1 + 1)
135 i = dx * dy
136
137 ov = i / (a1 + a2 - i)
138 ov[a1 + a2 - i < 0] = 0
139 return ov
140
141
142def simple_merge(rect1, rect2):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected