OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 07 Oct 2015 05:55:46 -0500Why degree from image is not the same at the theory in math?http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/ 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](/upfiles/14436839992436152.png)
![image description](/upfiles/14436842259764549.png)
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?Thu, 01 Oct 2015 02:22:56 -0500http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/Answer by LorenaGdL for <p>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.<a href="/upfiles/14436839992436152.png">C:\fakepath\degree.png</a></p>
<p><img alt="image description" src="/upfiles/14436842259764549.png"/></p>
<p>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?</p>
http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?answer=71983#post-id-71983*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).Thu, 01 Oct 2015 02:55:06 -0500http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?answer=71983#post-id-71983Comment by zms for <p><em>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.</em></p>
<p>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.</p>
<p>The <code>atan(a)</code> is positive when <code>a</code> 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).</p>
http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72035#post-id-72035A 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?Thu, 01 Oct 2015 22:18:28 -0500http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72035#post-id-72035Comment by StevenPuttemans for <p><em>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.</em></p>
<p>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.</p>
<p>The <code>atan(a)</code> is positive when <code>a</code> 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).</p>
http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72449#post-id-72449O 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...Wed, 07 Oct 2015 02:43:22 -0500http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72449#post-id-72449Comment by LorenaGdL for <p><em>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.</em></p>
<p>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.</p>
<p>The <code>atan(a)</code> is positive when <code>a</code> 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).</p>
http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72460#post-id-72460@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.Wed, 07 Oct 2015 04:03:55 -0500http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72460#post-id-72460Comment by Joan Charmant for <p><em>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.</em></p>
<p>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.</p>
<p>The <code>atan(a)</code> is positive when <code>a</code> 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).</p>
http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72026#post-id-72026@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.Thu, 01 Oct 2015 14:14:04 -0500http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72026#post-id-72026Comment by zms for <p><em>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.</em></p>
<p>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.</p>
<p>The <code>atan(a)</code> is positive when <code>a</code> 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).</p>
http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72438#post-id-72438@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.Wed, 07 Oct 2015 00:47:54 -0500http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72438#post-id-72438Comment by StevenPuttemans for <p><em>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.</em></p>
<p>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.</p>
<p>The <code>atan(a)</code> is positive when <code>a</code> 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).</p>
http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72068#post-id-72068@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?Fri, 02 Oct 2015 03:11:19 -0500http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72068#post-id-72068Comment by StevenPuttemans for <p><em>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.</em></p>
<p>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.</p>
<p>The <code>atan(a)</code> is positive when <code>a</code> 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).</p>
http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=71996#post-id-71996Also, 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](http://docs.opencv.org/modules/core/doc/utility_and_system_functions_and_macros.html?highlight=atan#float%20fastAtan2%28float%20y,%20float%20x%29).Thu, 01 Oct 2015 04:41:49 -0500http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=71996#post-id-71996Comment by StevenPuttemans for <p><em>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.</em></p>
<p>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.</p>
<p>The <code>atan(a)</code> is positive when <code>a</code> 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).</p>
http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72488#post-id-72488:D ow did not noticed that! Thanks for the explanation!Wed, 07 Oct 2015 05:55:46 -0500http://answers.opencv.org/question/71978/why-degree-from-image-is-not-the-same-at-the-theory-in-math/?comment=72488#post-id-72488