From 043efc311219c925f8c22518497f170a7f296dc5 Mon Sep 17 00:00:00 2001 From: Dhananjai Sharma <31407075+dhananjaisharma10@users.noreply.github.com> Date: Wed, 7 Aug 2019 01:06:17 -0400 Subject: [PATCH] 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. --- mmdet/datasets/transforms.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mmdet/datasets/transforms.py b/mmdet/datasets/transforms.py index aed6cff..1e13d77 100644 --- a/mmdet/datasets/transforms.py +++ b/mmdet/datasets/transforms.py @@ -49,18 +49,23 @@ class ImageTransform(object): return img, img_shape, pad_shape, scale_factor -def bbox_flip(bboxes, img_shape): - """Flip bboxes horizontally. +def bbox_flip(bboxes, img_shape, direction='horizontal'): + """Flip bboxes horizontally or vertically. Args: bboxes(ndarray): shape (..., 4*k) img_shape(tuple): (height, width) """ assert bboxes.shape[-1] % 4 == 0 - w = img_shape[1] flipped = bboxes.copy() - flipped[..., 0::4] = w - bboxes[..., 2::4] - 1 - flipped[..., 2::4] = w - bboxes[..., 0::4] - 1 + if direction == 'horizontal': + 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 -- GitLab