I’ve got a grid of 9 landmarks, shown in the picture below
My goal is to obtain warped image of a palm region, like this
Here, L1 on the source image is translated to point 0, 0 in the resulting image, L9 in the source image is translated to the bottom right corner of the resulting image
Here is my code.
import numpy as np
import cv2
source_points = np.array(
# L1 - L3, collected from image
[[[207., 39.],
[302., 35.],
[402., 28.],
# L4 - L6
[176., 144.],
[300., 124.],
[425., 100.],
# L7 - L9
[217., 250.],
[335., 211.],
[447., 174.]]])
w, h = 330, 330
target_points = np.array([[[0, 0],
[h/2, 0],
[h, 0],
[0, w/2],
[h/2, w/2],
[h, w/2],
[0, w],
[h/2, w],
[h, w]]])
tps_transformer = cv2.createThinPlateSplineShapeTransformer()
matches = [cv2.DMatch(i, i, 0) for i in range(source_points.shape[1])]
tps_transformer.estimateTransformation(source_points, target_points, matches)
trans_points = tps_transformer.applyTransformation(source_points)
warped_palm = tps_transformer.warpImage(source_crop)
When I check trans_points
, returned from tps_transformer.applyTransformation
, their values are correct.
>> print(trans_points.astype(int))
array([[[ 0, 0],
[165, 0],
[330, 0],
[ 0, 165],
[165, 165],
[330, 165],
[ 0, 329],
[165, 330],
[330, 330]]])
However, warping result is not that is desired