Ask Your Question

Why degree from image is not the same at the theory in math?

asked 2015-10-01 02:22:56 -0500

zms gravatar image

updated 2015-10-01 02:23:54 -0500

Hello, I have question on the degree calculated from the atan function between two points (x1,y1) and (x2,y2). From what I get from the online tutorial, the formula would be atan((y2-y1)/(x2-x1)) and convert it to degree later. Please refer to the image below.C:\fakepath\degree.png

image description

The question is, if there is negative degree value, in normal mathematical quadrant, it will be located in quadrant 2 and 4 but from the picture it shows that it is in quadrant 1 and 3. Am I correct in interpreting this degree in terms of image processing?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-10-01 02:55:06 -0500

LorenaGdL gravatar image

The question is, if there is negative degree value, in normal mathematical quadrant, it will be located in quadrant 2 and 4 but from the picture it shows that it is in quadrant 1 and 3.

While this comment is not correct or accurate, I understand your problem. In the traditional maths axes, the x-coordinate grows from the origin to the right of the horizontal axis, and the y-coordinate grows from the origin to the top of the vertical axis. In image processing, or at least in OpenCV, the convention is that the origin is located at the top-left corner, with the x-coordinate growing to the right of the horizontal axis and the y-coordinate growing to the bottom of the vertical axis. So, main difference is that y-axis is pointing downwards, so to say.

The atan(a) is positive when a is positive, and negative otherwise, so the mentioned change in axes convention leads to the results you're obtaining (which are correct, supposing you're using in both images point 1 to be the one in the left side and point 2 the one in the right side, i.e. you're calculating the minimum angle between the line connecting both points and a virtual horizontal line passing through the point at the bottom).

edit flag offensive delete link more



Also, just to add to this, atan() is not an OpenCV function, but a standard mathematical function from C++. There is however a fast calculation imbedded in OpenCV right here.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-10-01 04:41:49 -0500 )edit

@StevenPuttemans: This is an atan2 function, not the same as atan. It is indeed more appropriate for OP since atan alone cannot give the quadrant.

Joan Charmant gravatar imageJoan Charmant ( 2015-10-01 14:14:04 -0500 )edit

A details explaination on this matter. Thanks to everyone...

Since the C++: float fastAtan2(float y, float x) is being discussed, The function fastAtan2 calculates the full-range angle of an input 2D vector. The angle is measured in degrees and varies from 0 to 360 degrees. The accuracy is about 0.3 degrees.

Is it asking only for a point coordinate (float x and y) as input? For a line there might be two points of coordinate. Can the fast function being use?

zms gravatar imagezms ( 2015-10-01 22:18:28 -0500 )edit

@Joan Charmant, it is indeed not the same, but he wants the angle between two points and the function does this exactly, at high speed and with decent efficiency. So why not use it?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-10-02 03:11:19 -0500 )edit

@StevenPuttemans, the atan2() function is using only one coordinate points whereas the atan() will requires two coordinates for the result. I'm quite confuse how can it give the same answer.

zms gravatar imagezms ( 2015-10-07 00:47:54 -0500 )edit

O excuse me, it only calculates an angle of a vector, meaning from the origina to a point. That won't work if one of the two points is not in the origin...

StevenPuttemans gravatar imageStevenPuttemans ( 2015-10-07 02:43:22 -0500 )edit

@StevenPuttemans: but that's exactly the same issue with atan(), and the reason to use as point Point (x2-x1, y2-y1). With that subtraction you're virtually traslating your vector so that one of the points coincide with the origin, and as the angle is preserved, everything works fine.

LorenaGdL gravatar imageLorenaGdL ( 2015-10-07 04:03:55 -0500 )edit

:D ow did not noticed that! Thanks for the explanation!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-10-07 05:55:46 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-10-01 02:22:56 -0500

Seen: 224 times

Last updated: Oct 01 '15