Skip to content
Snippets Groups Projects
Commit 043efc31 authored by Dhananjai Sharma's avatar Dhananjai Sharma Committed by Kai Chen
Browse files

Added vertical flipping in bbox_flip (#1115)

* Added vertical flipping in bbox_flip

* Fixed linting errors

* Fixed linting errors

* Added a blank line in docstrings

* Fixed linting errors.
parent 5c2e68bb
No related branches found
No related tags found
No related merge requests found
...@@ -49,18 +49,23 @@ class ImageTransform(object): ...@@ -49,18 +49,23 @@ class ImageTransform(object):
return img, img_shape, pad_shape, scale_factor return img, img_shape, pad_shape, scale_factor
def bbox_flip(bboxes, img_shape): def bbox_flip(bboxes, img_shape, direction='horizontal'):
"""Flip bboxes horizontally. """Flip bboxes horizontally or vertically.
Args: Args:
bboxes(ndarray): shape (..., 4*k) bboxes(ndarray): shape (..., 4*k)
img_shape(tuple): (height, width) img_shape(tuple): (height, width)
""" """
assert bboxes.shape[-1] % 4 == 0 assert bboxes.shape[-1] % 4 == 0
w = img_shape[1]
flipped = bboxes.copy() flipped = bboxes.copy()
flipped[..., 0::4] = w - bboxes[..., 2::4] - 1 if direction == 'horizontal':
flipped[..., 2::4] = w - bboxes[..., 0::4] - 1 w = img_shape[1]
flipped[..., 0::4] = w - bboxes[..., 2::4] - 1
flipped[..., 2::4] = w - bboxes[..., 0::4] - 1
else:
h = img_shape[0]
flipped[..., 1::4] = h - bboxes[..., 3::4] - 1
flipped[..., 3::4] = h - bboxes[..., 1::4] - 1
return flipped return flipped
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment