这个问题与此问题有关:如何去除数独方格中的凸包缺陷
我试图在Mathematica to OpenCV-Python
中实现nikie的答案
,但我卡在了过程的最后一步。
也就是说,我在正方形中获得了所有交点,如下所示:
现在,我想将其转换为一个大小为(450,450)的完美正方形,如下所示:
(不要介意两个图像之间的亮度差异)。
问题:
我如何在OpenCV-Python中完成这个操作?我正在使用cv2
版本。
这个问题与此问题有关:如何去除数独方格中的凸包缺陷
我试图在Mathematica to OpenCV-Python
中实现nikie的答案
,但我卡在了过程的最后一步。
也就是说,我在正方形中获得了所有交点,如下所示:
现在,我想将其转换为一个大小为(450,450)的完美正方形,如下所示:
(不要介意两个图像之间的亮度差异)。
问题:
我如何在OpenCV-Python中完成这个操作?我正在使用cv2
版本。
这是扭曲后的结果:
这里是代码:
import cv2
from scipy.interpolate import griddata
import numpy as np
grid_x, grid_y = np.mgrid[0:149:150j, 0:149:150j]
destination = np.array([[0,0], [0,49], [0,99], [0,149],
[49,0],[49,49],[49,99],[49,149],
[99,0],[99,49],[99,99],[99,149],
[149,0],[149,49],[149,99],[149,149]])
source = np.array([[22,22], [24,68], [26,116], [25,162],
[64,19],[65,64],[65,114],[64,159],
[107,16],[108,62],[108,111],[107,157],
[151,11],[151,58],[151,107],[151,156]])
grid_z = griddata(destination, source, (grid_x, grid_y), method='cubic')
map_x = np.append([], [ar[:,1] for ar in grid_z]).reshape(150,150)
map_y = np.append([], [ar[:,0] for ar in grid_z]).reshape(150,150)
map_x_32 = map_x.astype('float32')
map_y_32 = map_y.astype('float32')
orig = cv2.imread("tmp.png")
warped = cv2.remap(orig, map_x_32, map_y_32, cv2.INTER_CUBIC)
cv2.imwrite("warped.png", warped)
cv2.remap
,但不知道如何使用。但是必须使用scipy吗?不能只用numpy和cv2吗?此外,是否可以在单个步骤中对整个图像使用相同的方法(即无需将其拆分为子块)? - Abid Rahman K