OpenCV学习(7)-极坐标变换

本文介绍了一种基于Python和OpenCV实现的图像从笛卡尔坐标到极坐标的转换方法,并展示了具体的实现代码及效果对比。该方法可用于图像分析、目标检测等多种计算机视觉任务。
# -*- 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:",
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值