Imagemagick 的+distort DePolar
documentation表示该命令将图像从极坐标转换为笛卡尔坐标并保留极坐标图像的纵横比。
在 OpenCV 中有类似的东西吗?我一直在看linearPolar
,但功能似乎更复杂。
编辑 linearPolar
接近于 +distort DePolar
,但是 Imagemagick 命令正确地改变了结果图像的大小,而 linearPolar
不会改变尺寸。
warpPolar
是正确的函数,因为它允许指定 dsize
,这与 linearPolar
不同。
下面是产生与 Imagemagick 命令基本相同结果的代码:
import cv2 as cv
import numpy as np
def undistort(img):
height, width, *_ = img.shape
assert height == width, "we want a square image"
radius = int(height / 2)
image_center = radius, radius
dest_width = int(np.ceil(np.pi * radius))
dest_height = int(np.ceil(radius))
dest_size = (dest_height, dest_width)
undistorted_img = cv.warpPolar(src=img, dsize=dest_size, center=image_center, maxRadius=radius, flags=0)
return cv.rotate(undistorted_img, cv.ROTATE_90_CLOCKWISE)
我是一名优秀的程序员,十分优秀!