Python-opencv实现极坐标变换

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()
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员阿明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值