Miranda Miranda - 5 months ago 23
Python Question

cv2.phase gives the angle in radian

I'm trying to get the orientation of the gradient through the Sobel function in opencv python. The problem is when I provide the gradient in the x and y direction to the phase function, it always gives me the same result, no matter phase in degree is true or False. Here is the sample code:

img = cv2.imread('frameBB.jpg',0)
sobelx = cv2.Sobel(img,cv2.CV_32F,1,0,ksize=3)
sobely= cv2.Sobel(img,cv2.CV_32F,0,1,ksize=3)

I then get the histogram of phase, and end up with the same result for the last argument of phase function being either True, or False. The histogram looks like this for both cases. enter image description here

this is how the original image and its gradient images look like:

enter image description here

I am not sure what I am doing wrong here, and why I get the gradient angle in radian for both cases.


As you can see from the documentation here for cv2.phase:

cv2.phase(x, y[, angle[, angleInDegrees]])

the third positional argument is not in fact for specifying degrees/radians, it's used for the output array. The argument you are trying to change is angleInDegrees. You can either specify it as the 4th positional argument, or more clearly by using a keyword as such: