OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 23 Jan 2013 08:45:23 -0600Question about polar or radial angle calculation in the image coordinate systemhttp://answers.opencv.org/question/6344/question-about-polar-or-radial-angle-calculation-in-the-image-coordinate-system/Hi,
I have general questions, not explicitly about OpenCV, but related to image processing: The image coordinate system normally has the x-axis pointing from left to right, and the y-axis pointing DOWNWARDS. However, in math, normally, the y-axis points upwards.
1. Therefore, is a correction needed to account for the orientation of the y-axis, say, while doing tangentInverse(y, x) to get the radial angle of the pixel location?
2. Will doing y' = height - 1- y, and calling tangentInverse(y', x), solve the problem? (height = image height)
3. The confusion began after I had tried to relate to the formula for the principal value on the "Polar coordinate system" page of wikipedia (specifically, the one that deals with x and y being in different quadrants). I will appreciate, if any expert could clarify. Thank you.Tue, 22 Jan 2013 01:13:17 -0600http://answers.opencv.org/question/6344/question-about-polar-or-radial-angle-calculation-in-the-image-coordinate-system/Answer by Haris for <p>Hi,</p>
<p>I have general questions, not explicitly about OpenCV, but related to image processing: The image coordinate system normally has the x-axis pointing from left to right, and the y-axis pointing DOWNWARDS. However, in math, normally, the y-axis points upwards. </p>
<ol>
<li><p>Therefore, is a correction needed to account for the orientation of the y-axis, say, while doing tangentInverse(y, x) to get the radial angle of the pixel location? </p></li>
<li><p>Will doing y' = height - 1- y, and calling tangentInverse(y', x), solve the problem? (height = image height) </p></li>
<li><p>The confusion began after I had tried to relate to the formula for the principal value on the "Polar coordinate system" page of wikipedia (specifically, the one that deals with x and y being in different quadrants). I will appreciate, if any expert could clarify. Thank you.</p></li>
</ol>
http://answers.opencv.org/question/6344/question-about-polar-or-radial-angle-calculation-in-the-image-coordinate-system/?answer=6393#post-id-6393I am not sure this is the exact answer for you question but may be helpful. If you consider an image and you want to find the angle at any point from 0,0 you can consider the image as third quadrant and you will get angle in the range of -90 to -179.99 using [atan2()](http://www.cplusplus.com/reference/cmath/atan2/). And if your reference is centre of the image the upper quadrants will be in the range of 0 to 180 and the lower quadrants gives approximately -.1 to -179.99. The below code may give you the idea about the arc tangent of any point in the given image. You can use mouse click to point out the co-ordinates.
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
Point p1;
Mat frame, src;
Point cent = Point(300,300);// for calculating tangent from center of image
double angle=0;
char name[20];
void mouseHandler(int event, int x, int y, int flags, void *param)
{
switch(event) {
/* left button down */
case CV_EVENT_LBUTTONDOWN:
p1.x=x;
p1.y=y;
frame.copyTo(src);
line(src, p1, cent,Scalar(255,0,0),2, 8 );
angle = atan2(cent.y - p1.y,cent.x - p1.x) * 180.0 / CV_PI;
sprintf(name,"Angle = %f degree",angle);
putText(src,name, Point(30,30), FONT_HERSHEY_SIMPLEX,1, Scalar(0,255,0),2);
imshow("out", src);
break;
}
}
int main(int argc, char** argv)
{
frame= Mat(600,600,CV_8UC3);
frame.copyTo(src);
namedWindow("out", 0);
imshow("out", src);
setMouseCallback( "out", mouseHandler, NULL );
waitKey(0);
return 0;
}
Hope these Helpful.....
Wed, 23 Jan 2013 08:45:23 -0600http://answers.opencv.org/question/6344/question-about-polar-or-radial-angle-calculation-in-the-image-coordinate-system/?answer=6393#post-id-6393