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?


1 Answer 1


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



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


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


Similar for height

  1. The center x is given by


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

  • $\begingroup$ Thank you so much. It worked and I am surprised how simple these formulas are. Struggling too much prevents seeing simple solutions I think. $\endgroup$ Nov 17, 2021 at 7:10
  • $\begingroup$ Your assumption is right. The location of the center point is not affected by the rotation angle of the rectangle. $\endgroup$ Nov 17, 2021 at 7:13
  • $\begingroup$ Glad it helped. Visualizing the shape makes it easier. $\endgroup$
    – Nikos M.
    Nov 17, 2021 at 9:00
  • $\begingroup$ Well, what if the starting point of the coordinates of the rectangle is not always started from the top left corner but from random corner and I always want to calculate the positive angle of the rectangle w.r.t x axis? How can you pick proper coordinates to calculate angle? $\endgroup$ Nov 17, 2021 at 12:45
  • 2
    $\begingroup$ I think step 3 (in above answer by Nikos M.) should be... The center x is given by: $ cx = \frac{x_1 + x_3}{2} $ $\endgroup$
    – t-flow
    Aug 11, 2022 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.