Dear all,
I am trying to warp an image using the thinplatespline but after warping, the image contains only 0 values. I am attaching a working code example and the datasets as well. I hope for some help to show me the right path again…
import cv2
import numpy as np
from PIL import Image
pts1 = np.array([[[1000., 1000.], [1000., 2800.], [1000., 4600.], [1000., 6400.],
[1000., 7667.], [2800., 1000.], [2800., 2800.], [2800., 4600.],
[2800., 6400.], [2800., 7667.], [4600., 1000.], [4600., 2800.],
[4600., 4600.], [4600., 6400.], [4600., 7667.], [6400., 1000.],
[6400., 2800.], [6400., 4600.], [6400., 6400.], [6400., 7667.],
[7667., 1000.], [7667., 2800.], [7667., 4600.], [7667., 6400.],
[7667., 7667.]]])
pts2 = np.array([[[1007., 989.], [1006., 2789.], [1005., 4586.], [1005., 6386.],
[1002., 7653.], [2808., 989.], [2808., 2785.], [2806., 4586.],
[2802., 6387.], [2801., 7654.], [4605., 992.], [4598., 2792.],
[4595., 4590.], [4593., 6390.], [4594., 7656.], [6390., 1000.],
[6392., 2797.], [6388., 4597.], [6391., 6392.], [6390., 7659.],
[7655., 1006.], [7654., 2802.], [7654., 4600.], [7654., 6395.],
[7654., 7662.]]])
image = np.array(Image.open('image.jpg'))
bufferzise = 2000
imbuffer = np.zeros((image.shape[0] + bufferzise,
image.shape[1] + bufferzise))
imbuffer[int(1000):int(1000 + image.shape[0]),
int(1000):int(1000 + image.shape[1])] = image[:, :]
matches = list()
for ipoint in range(0, pts1.shape[1]):
matches.append(cv2.DMatch(ipoint, ipoint, 0))
tps = cv2.createThinPlateSplineShapeTransformer()
tps.estimateTransformation(pts2, pts1, matches)
out_img = tps.warpImage(imbuffer)