applyTransformation not working in python?
Trying to work with the Thin Plate Spline warping in python. The actual warping works just fine:
tps = cv2.createThinPlateSplineShapeTransformer()
pts1 = [(10, 10), (100, 100), (50, 100), (200, 30), (60, 20), (150, 200), (120, 90)]
pts2 = [(15, 5), (110, 105), (55, 105), (190, 35), (70, 20), (155, 205), (115, 95)]
cv2.imread("input.png")
matches = [cv2.DMatch(i, i, 0) for i in range(7)]
tps.estimateTransformation(np.array(pts1).reshape((-1, 7, 2)), np.array(pts2).reshape((-1, 7, 2)), matches)
dst = tps.warpImage(img)
cv2.imwrite('warped.png', dst)
The problem seems to be in the applyTransformation. I'd expect that the transform from points in pts1 should lead to points in pts2, but it seems the transform maps all points to a single (wrong) point:
>>> tps.applyTransformation(np.array((10,10)).reshape((-1, 1, 2)))
(7.34408968128264e-05, array([[[ 4.386129 , -6.4083347]]], dtype=float32))
>>> tps.applyTransformation(np.array((100,100)).reshape((-1, 1, 2)))
(7.34408968128264e-05, array([[[ 4.386129 , -6.4083347]]], dtype=float32))
What can be the issue? OpenCV version is 3.4.2.
it's the other way round
@berak fine, but different points should still map differently, and to reasonable coordinates.
@berak - Moreover, all points map to a single point - that is clearly wrong behavior.
Did you solve your problem? I am also in trouble with this.
@kian -- however, please do not post answers here, if you have a question or a comment, thank you.
I'm also having the same issue. warpImage() works fine but applyTransformation() gives wrong mapped points.