0

I need to deform an image moving one (or more) point from its position to a different destination.
The following example (generated using warp function in Photoshop) clarifies the problem:

BEFORE
Before

AFTER
After

In the example point (100,100) has been stretched to the new position (200,200).

I tried using the warp solutions provided by OpenCV:

input_pts = np.float32([(100, 100), (400, 100), (400, 400), (100, 400)])
output_pts = np.float32([(200, 200), (400, 100), (400, 400), (100, 400)])
(M, _) = cv2.findHomography(input_pts, output_pts)
# M = cv2.getPerspectiveTransform(input_pts, output_pts)
out = cv2.warpPerspective(test_img, M, (500, 500), flags=cv2.INTER_AREA)

and

input_pts = np.float32([(100, 100), (400, 100), (100, 400)])
output_pts = np.float32([(200, 200), (400, 100), (100, 400)])
M = cv2.getAffineTransform(input_pts, output_pts)
out = cv2.warpAffine(test_img.copy(), M, (500, 500), flags=cv2.INTER_LINEAR)

without success.

I'm wondering what could be the best approach to solve this problem.

Nico
  • 113
  • 8
  • You have to define the warp transformation equations that you want to use when moving one or more points. Photoshop seems to be using some non-linear transformation. Looks like some kind of spline. – fmw42 Jan 01 '22 at 17:15
  • with opengl or other, it would be easy enough to define a triangle/quad mesh, texture it, deform the mesh, and draw the result. – Christoph Rackwitz Jan 01 '22 at 19:06
  • You may be interested in this [post](https://stackoverflow.com/questions/53907633/how-to-warp-an-image-using-deformed-mesh/72428493#72428493) – WhaSukGO May 30 '22 at 02:28

0 Answers0