OpenCV inverse warpPolar 输出帧外

OpenCV inverse warpPolar output out of frame

当我尝试对我的图像进行逆极坐标变换时,输出在输出图像之外。顶部还有一些奇怪的白色图案。我试图使输出图像更大,但圆圈在左侧,所以没有帮助。

我正在尝试使用 warpPolar 函数制作一个线圆,首先我翻转线并给它一个黑色区域,如图所示,然后使用 cv2.warpPolar 函数和 WARP_INVERSE_MAP旗帜。

如何完整地绘制圆,并得到它的边界框是我的问题。

line = np.ones(shape=(20,475),dtype=np.uint8)*255

flipped = cv2.rotate(line,cv2.ROTATE_90_CLOCKWISE)
cv2.imshow('flipped',flipped)

h,w = flipped.shape

radius = int(h / (2*np.pi)) 

new_image = np.zeros(shape=(h,radius+w),dtype=np.uint8)
h2,w2 = new_image.shape

new_image[: ,w2-w:w2] = flipped
cv2.imshow('polar',new_image)

h,w = new_image.shape

center = (w/2,h) 

output= cv2.warpPolar(new_image,center=center,maxRadius=radius,dsize=(1500,1500),flags=cv2.WARP_INVERSE_MAP + cv2.WARP_POLAR_LINEAR)

cv2.imshow('output',output)
cv2.waitKey(0)

注意:当我尝试相同的代码时,我得到的结果与上面显示的结果不同。您可能会漏掉一些要添加的代码行 ?

如果我没有误解你的问题,你试图得到这个结果:(如果我错了,我会相应地更新答案)

您唯一缺少的一点是定义中心和半径。您在这里进行逆变换,输入是由您创建的,而不是 warpPolar。由于您将大小定义为 (1500,1500),因此您需要相应地更新中心和半径。这是我的代码给出的结果:

import cv2
import numpy as np


line = np.ones(shape=(20,475),dtype=np.uint8)*255

flipped = cv2.rotate(line,cv2.ROTATE_90_CLOCKWISE)
cv2.imshow('flipped',flipped)

h,w = flipped.shape

radius = int(h / (2*np.pi)) 

new_image = np.zeros(shape=(h,radius+w),dtype=np.uint8)
h2,w2 = new_image.shape

new_image[: ,w2-w:w2] = flipped
cv2.imshow('polar',new_image)

h,w = new_image.shape

center = (750,750) 


maxRadius = 750



output= cv2.warpPolar(new_image,center=center,maxRadius=radius,dsize=(1500,1500),flags=cv2.WARP_INVERSE_MAP + cv2.WARP_POLAR_LINEAR)

cv2.imshow('output',output)
cv2.waitKey(0)