How to convert horizontal bounding box coordinates to oriented bounding box coordinates

I am trying to detect oriented bounding boxes with faster rcnn for a long time, but I could not make it to do so. I aim to detect objects in the DOTA dataset. I was using built-in faster rcnn model in pytorch, but realized that it does not support OBB. Then I found another library named detectron2 that is built on the pytorch framework. Built-in faster rcnn network in detectron2 is actually compatible with OBB but I could not make that model work with DOTA. Because I could not convert DOTA box annotations to (cx, cy, w, h, a). In DOTA, objects are annotated by coordinates of 4 corners which are (x1,y1,x2,y2,x3,y3,x4,y4).

I can't come up with a solution that converts these 4 coordinates to (cx, cy, w, h, a), where cx and cy are the center point of OBB and w, h, and a are width, height and angle respectively.

Is there any suggestion?

Topic faster-rcnn object-detection pytorch deep-learning python

Category Data Science


Assuming the rectangle is as below (easily adjusted if otherwise)

rectangle

Then:

  1. The tangent of the angle of rotation is given by

$tan(a)=\frac{y_3-y_2}{x_3-x_2}$

Depending on quadrant of interest one can take the opposite coordinates. Getting the inverse tan function gives the angle in radians.

  1. The width is given by

$w=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}$

Similar for height

  1. The center x is given by

$cx=\frac{x_1+x_2}{2}$

And similar for cy. Rotation is assumed to leave center unaffected.

Please comment if any of these is not clear enough, or you have problems applying it .

(posted from my smartphone)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.