Upload box_overlaps.py (#9)
Browse files- Upload box_overlaps.py (f517391923c50393890bb70ffc73b6d4f8cc2b93)
Co-authored-by: Hongyang Wei <[email protected]>
widerface_evaluate/box_overlaps.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
def bbox_overlaps(boxes, query_boxes):
|
| 4 |
+
"""
|
| 5 |
+
Parameters
|
| 6 |
+
----------
|
| 7 |
+
boxes: (N, 4) ndarray of float
|
| 8 |
+
query_boxes: (K, 4) ndarray of float
|
| 9 |
+
Returns
|
| 10 |
+
-------
|
| 11 |
+
overlaps: (N, K) ndarray of overlap between boxes and query_boxes
|
| 12 |
+
"""
|
| 13 |
+
N = boxes.shape[0]
|
| 14 |
+
K = query_boxes.shape[0]
|
| 15 |
+
overlaps = np.zeros((N, K), dtype=np.float)
|
| 16 |
+
|
| 17 |
+
box_area = (
|
| 18 |
+
(query_boxes[:, 2] - query_boxes[:, 0] + 1) *
|
| 19 |
+
(query_boxes[:, 3] - query_boxes[:, 1] + 1)
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
for n in range(N):
|
| 23 |
+
iw = (
|
| 24 |
+
np.maximum(0, np.minimum(boxes[n, 2], query_boxes[:, 2]) -
|
| 25 |
+
np.maximum(boxes[n, 0], query_boxes[:, 0]) + 1)
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
ih = (
|
| 29 |
+
np.maximum(0, np.minimum(boxes[n, 3], query_boxes[:, 3]) -
|
| 30 |
+
np.maximum(boxes[n, 1], query_boxes[:, 1]) + 1)
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
ua = (
|
| 34 |
+
(boxes[n, 2] - boxes[n, 0] + 1) *
|
| 35 |
+
(boxes[n, 3] - boxes[n, 1] + 1) +
|
| 36 |
+
box_area - iw * ih
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
overlaps[n, :] = np.where((iw > 0) & (ih > 0), iw * ih / ua, 0)
|
| 40 |
+
|
| 41 |
+
return overlaps
|