Speed up bbox_clip (#177)

* Speed up bbox_clip

* Update geometry.py
pull/180/head
lizz 2020-02-05 15:17:42 +08:00 committed by GitHub
parent d6ce3a2e1b
commit 0874642fb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -76,11 +76,10 @@ def bbox_clip(bboxes, img_shape):
ndarray: Clipped bboxes.
"""
assert bboxes.shape[-1] % 4 == 0
clipped_bboxes = np.empty_like(bboxes, dtype=bboxes.dtype)
clipped_bboxes[..., 0::2] = np.maximum(
np.minimum(bboxes[..., 0::2], img_shape[1] - 1), 0)
clipped_bboxes[..., 1::2] = np.maximum(
np.minimum(bboxes[..., 1::2], img_shape[0] - 1), 0)
cmin = np.empty(bboxes.shape[-1], dtype=bboxes.dtype)
cmin[0::2] = img_shape[1] - 1
cmin[1::2] = img_shape[0] - 1
clipped_bboxes = np.maximum(np.minimum(bboxes, cmin), 0)
return clipped_bboxes