cartToPolar is a function in OpenCV that can be used to compute the magnitude and angle of 2D vectors. You provide a matrix of 2D vectors as two Mat structures, one holding the X component of the vectors and the other for the Y component. cartToPolar returns two Mat structures, one holding the magnitude and the other the angle of the vectors.
Note that the angle returned is in the range 0 to 360 degrees. This is different from the typical output of the atan2 function, which is in the range of 180 to +180 degrees. To match the result of atan2 to the angle output of cartToPolar, you would need to do this:
float ang = atan2(y, x) * 180 / PI; if (ang < 0) ang = 360 + ang;

The documentation of cartToPolar is here.

The source code of cartToPolar can be seen in
modules/core/src/mathfuncs.cpp
, which can be seen here. 
The computation of the angle can be seen in the FastAtan2_32f function in
modules/core/src/mathfuncs.cpp
, which can be seen here.