Skip to content
Advertisement

How to rotate a rectangle/bounding box together with an image

I’m working on a data augmentation and im trying to generate synthetic version of every image in my dataset. So i need to rotate images and together with bounding boxes as well in the images.

im only going to rotate images by 90, 180, 270 degrees.

I’m using pascal-voc annotation format as shown here. As a result i have following info.

x_min, y_min, x_max, y_max. Origin of image(i can get it from image size)

i’ve searched a lot on it. But i couldnt find any solution for rotating bounding boxes( or rectangles)

i’ve tried something like this; i’ve got this solution from here and tried to adapt it but didnt work.

JavaScript

thanks.

EDIT:

I need to get this rotation together with image and bounding box. First picture is original one, second one is rotated as 90 degree(counter-clockwise) and 3rd picture is rotated as -90 degree (counter-wise). i tried to rotate manually on paint to be precise. So i got these results.

JavaScript

Image Rotations; Original, 90 rotation, -90 rotation

Advertisement

Answer

i’ve found simpler way. enter image description here

Base on this aproach. We can do this calculation without using trigonometric calculations like this:

JavaScript

this can be used over and over again. And returns new bounding boxes values in Pascal-voc format.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement