我尝试按照此链接对图像进行变形
https://github.com/aydal/Cylinderical-Anamorphosis/blob/master/anamorph.py
它给出了一个变形的图像,但它给出了半圆形的图像。但我想要一个完整的圆圈大小的输出。我试过了
warp[c-j, i-1] = img[p-1, q-1]
warp[c+j, i-1] = img[p-1, q-1]
代替warp[c-j, i-1] = img[p-1, q-1]
但它不会在整个圆圈中给出一张图像,而是两次创建相同的输出!
谁能帮帮我吗。
完整代码:
import math
from cv2 import *
import numpy as np
img = imread("test.jpg")
(rows, cols) = (img.shape[0], img.shape[1])
r = 0 #offset-gives space to keep cylinder and height of the image from bottom: original: math.trunc(.25*rows)
c = rows #this will be the decisive factor in size of output image-maximum radius of warped image: original: c = r+rows
warp = np.zeros([c,2*c,3], dtype=np.uint8)
def convert(R, b):
return math.trunc(b*rows/(2*math.asin(1))), math.trunc(c-R)
for i in range(0, 2*c):
for j in range(1, c):
b = math.atan2(j, i-c)
R = math.sqrt(j*j+math.pow(i-c, 2))
if R>=r and R<=c:
(q, p) = convert(R, b)
warp[c-j, i-1] = img[p-1, q-1]
#warp[c+j, i-1] = img[p-1, q-1]
imshow("Output", warp)
waitKey()