How to deform an image with python moving one single point to a different position

515 views Asked by At

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.

0

There are 0 answers