# -*- coding: utf-8 -*-
import sys
import cv2
import numpy as np
def polar(I,center,r,theta=(0,360),rstep=1.0,thetastep=360.0/(180*8)):
#获取极坐标变换中心坐标
cx,cy=center
#获取距离的最小和最大范围
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)#生成等差数列,minr起始,maxr终止,生成h个
r=np.tile(r,(w,1))
r=np.transpose(r)#r转置
theta=np.linspace(mintheta,maxtheta,w)
theta=np.tile(theta,(h,1))
x,y=cv2.polarToCart(r,theta,angleInDegrees=True)
#print("x:\n",x)
#print(x.shape)
#最近邻插值
for i in range(h):
#print('')
for j in range(w):
px=int(round(x[i][j])+cx)
py=int(round(y[i][j])+cy)
#print(px)
if ((px>=0 and px<=w-1) and (py>=0 and py<=h-1)):
#print(I[py][px])
#print("j:",
OpenCV学习(7)-极坐标变换
最新推荐文章于 2023-08-26 00:46:30 发布
本文介绍了一种基于Python和OpenCV实现的图像从笛卡尔坐标到极坐标的转换方法,并展示了具体的实现代码及效果对比。该方法可用于图像分析、目标检测等多种计算机视觉任务。

最低0.47元/天 解锁文章
1377

被折叠的 条评论
为什么被折叠?



