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

标签 opencv imagemagick imagemagick-convert

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/

相关文章:

Android+android-ndk-r10d+OpenCV-2.4.10 编译报错

python - 在 Python 类中使用鼠标事件回调

ruby - 使用 Ruby 和 imagemagick 获取或计算图像的熵

parallel-processing - ImageMagick 转换和 GNU 并行在一起

c++ - 将图像存储在数组中

c++ - 在 OpenCV 中如何知道图像是否为 RGB?

python-2.7 - python wand.image 无法识别

PHP 缩略图类

php - 使用 ImageMagic 将 SVG 转换为 PNG 会忽略填充图案 url

linux - 在子目录中将图像转换为 pdf