C++ OpenCV cv::polarToCart()

C++ OpenCV cv::polarToCart()

The C++ article polarToCart() is used to calculate the x and y co-ordinates from the given magnitude and angle.This can particularly be used in object detection when we specifiacally want to locate a specific part out of the entire object.The input is in two arrays, magnitude and angle, of the same size and type, specifying the magnitude and angle of the field at every point. The output is similarly two arrays that will be of the same size and type as the inputs, and which will contain the x and y projections of the vector at each point. The additional flag angleInDegrees will cause the angle array to be interpreted as angles in degrees rather than in radians.


void polarToCart(InputArray magnitude, InputArray angle, OutputArray x, OutputArray y, bool angleInDegrees=false)

  1.  magnitude - input floating-point array of magnitudes of 2D vectors; it can be an empty matrix (=Mat()), in this case, the function assumes that all the magnitudes are =1; if it is not empty, it must have the same size and type as 'angle'.
  2. angle - input floating-point array of angles of 2D vectors.
  3. x - output array of x-coordinates of 2D vectors; it has the same size and type as 'angle'.
  4. y -output array of y-coordinates of 2D vectors; it has the same size and type as 'angle'.
  5. angleInDegrees - when true, the input angles are measured in degrees, otherwise, they are measured in radians.
The function polarToCart calculates the Cartesian coordinates of each 2D vector represented by the corresponding elements of magnitude and angle :
  • x(I)=magnitude(I)*cos(angle(I))              
  • y(i)=magnitude(I)*sin(angle(I))