import cv2
import numpy as np
def polar(I,center,r,theta=(0,360),rstep=1.0,thetastep=360.0/(180*8)):
minr,maxr=r
mintheta,maxtheta=theta
H=int((maxr-minr)/rstep)+1
W=int((maxtheta-mintheta)/thetastep)+1
o=125*np.ones((H,W),I.dtype)
r=np.linspace(minr,maxr,H)
r=np.tile(r,(W,1))
r=np.transpose(r)
theta=np.linspace(mintheta,maxtheta,W)
theta=np.tile(theta,(H,1))
x,y=cv2.polarToCart(r,theta,angleInDegrees=True)
for i in range(H):
for j in range(W):
px=int(round(x[i][j])+cx)
py = int(round(y[i][j]) + cy)
if ((px>=0 and px<=w-1) and (py>=0 and py<=h-1)):
o[i][j]=I[py][px]
return 0
I=cv2.imread("/home/xiaomingming/profile/clcock.jpg",cv2.IMREAD_GRAYSCALE)
h,w=I.shape[:2]
cx,cy=508,503
cv2.circle(I,(int(cx),int(cy)),10,(255.0,0,0),3)
o=polar(I,(cx,cy),(200,550))
o=cv2.flip(o,0)
cv2.imshow("I",I)
cv2.imshow("o",o)
cv2.waitKey(0)
cv2.destroyAllWindows()
Python-opencv实现极坐标变换
最新推荐文章于 2024-08-26 13:46:11 发布