drawing orientation axes of a rotated bounding box

asked 2014-11-12 12:26:47 -0600

theodore gravatar image

I have an object from which I extract the contours and as consequence the minimum rotated bounding box. From the latter I can successfully obtain the center point (i.e. Point(box.center.x, box.center.y)) and the angle (i.e. box.angle) of the box, respectively. Now I want to draw the new orientation axes of the rotated box. In order to achieve that I followed the following formula:

x2 = x1 + length * cos(θ)
y2 = y1 + length * sin(θ)

where θ should be in radians (right?), box.angle provides the angle already in radians, isn't that right? So, there is not need to make the following transformation:

θ = angle * 3.14 / 180.0

However, doing the following:

int length = 150;
Point p1 = Point(box.center.x, box.center.y);
Point p2;

p2.x =  (int)round(p1.x + length * cos(angle));
p2.y =  (int)round(p1.y + length * sin(angle));
line(img, p1, p2, CV_RGB(0, 255, 0));

does not give the correct result for the new x-axis. What am I missing, can someone provide me with a hint. Thanks in advance ;-)

edit retag flag offensive close merge delete

Comments

2

y points down in opencv ((0,0) is top-left)

berak gravatar imageberak ( 2014-11-13 02:17:33 -0600 )edit