opencv3.0线性极坐标变换,python
对数极坐标变换:
import math import numpy as np import cv2 def print_hi(str): print('hi,'+str) def print_3(str): print('hi3,'+str) def polar2(I, center, r, theta=(0, 360), rstep=0.52, thetastep=360.0/(180*8)): #def polar2(I, center, r, theta=(0, 360), rstep=0.5, thetastep=1.0/4): """ 最近邻插值方法 """ cx, cy = center minr, maxr = r mintheta, maxtheta = theta h = int((maxr-minr)/rstep)+1 w = int((maxtheta-mintheta)/thetastep)+1 O33 = 125*np.ones((h, w), I.dtype) #cv2.imshow('i',O33) # 极坐标变换 r = np.linspace(minr, maxr, h) # 生成等差数列,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)) x1, y1 = cv2.polarToCart(r, theta, angleInDegrees=True) # 默认是角度表示,也可以幅度表示 # 最近邻插值 for i in range(h): for j in range(w): px = int(round(x1[i][j])+cx) #近邻 py = int(round(y1[i][j])+cy) #近邻 if ((px >= 0 and px <= w-1) and (py >= 0 and py <= h-1)): O33[i][j] = I[py][px] return O33 if __name__ == "__main__": print_hi('极坐标') print('坐标11,13以0,0为中心极坐标转换') I = cv2.imread(r'clock2.png', cv2.IMREAD_GRAYSCALE) #dst = cv2.linearPolar(I,(390,370),390,cv2.INTER_LINEAR) #opencv3.0线性极坐标变换, M = 100 #系数,越大越好 dst = cv2.logPolar(I,(390,370),M,cv2.WARP_FILL_OUTLIERS) #opencv3.0对数极坐标变换 dst = cv2.rotate(dst,2) # 0:0度,1:90度 cv2.imwrite('duishu.jpg',dst) cv2.imshow('O33', dst) cv2.waitKey(0) cv2.destroyAllWindows()
欢迎讨论,相互学习。
cdtxw@foxmail.com
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
2021-02-26 关于VS2005使用VC++创建MFC智能设备应用程序,总是创建失败解决方法
2020-02-26 cb50a_c++_STL_算法_局部排序partial_sort
2020-02-26 cb49a_c++_STL_算法_对所有元素排序_sort_stable_sort
2020-02-26 cb48a_c++_STL_算法_重排和分区random_shuffle_stable_partition