gpt4 book ai didi

opencv - Imagemagick 的 `+distort DePolar` 的 OpenCV 等价物是什么

转载 作者:太空宇宙 更新时间:2023-11-03 22:39:18 26 4
gpt4 key购买 nike

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)

关于opencv - Imagemagick 的 `+distort DePolar` 的 OpenCV 等价物是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55672177/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com