Ask Your Question

Question about polar or radial angle calculation in the image coordinate system

asked 2013-01-22 01:13:17 -0600

HW gravatar image

updated 2015-09-26 08:20:11 -0600


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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-01-23 08:45:23 -0600

Haris gravatar image

updated 2015-09-26 08:19:29 -0600

I 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(). 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 */


         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);

int main(int argc, char** argv)
  frame= Mat(600,600,CV_8UC3);
  namedWindow("out", 0);
  imshow("out", src);
  setMouseCallback( "out", mouseHandler, NULL );
  return 0;

Hope these Helpful.....

edit flag offensive delete link more

Question Tools


Asked: 2013-01-22 01:13:17 -0600

Seen: 1,688 times

Last updated: Sep 26 '15