2

I am trying to transform an image such that straight lines/boxes become curvy.

Unfortunately I am only able to change the perspective of the images using Affine transformations. Which only makes line non-parallel if they were parallel before, the lines remain straight. I do not know which functions can bring curvy transformations.

hz_error,vert_error = 10,5
w,h,_=img.shape
src = np.float32([(0,0),(w,0),(w,h),(0,h)])
dst = np.float32([(-hz_error,-vert_error),(w+hz_error,-vert_error),(w-hz_error,h+vert_error),(0,h)])
M = cv2.getPerspectiveTransform(src, dst)
warped = cv2.warpPerspective(img, M, (w+20, h+20))

The input image Actual The output image Result The output that I require should be a curvy image.

An example desirable output, Desirable Here the edges are "curvy" rather than straight.

REVOLUTION
  • 130
  • 2
  • 12
  • There are an infinite number of transformations that make lines curvy. Any idea on how they should curve? – Cris Luengo Aug 01 '19 at 13:38
  • Use a 4 point perspective transformation much the same as your affine but using 4 points rather than 3. That will slant the lines as per your desired "curvy" result. Note that your use of "curvy" is wrong. It is slanted (parallelogram) not curvy. – fmw42 Aug 01 '19 at 17:52
  • @fmw42 The code that I wrote only generates quadrilaterals because of the nature of the transform. If we apply perspective transform on a straight line it remain a straight line. I wanted a transformation which can make straight lines curvy. I added an example curvy image. – REVOLUTION Aug 07 '19 at 12:18
  • @CrisLuengo I added an example desirable output image. It is basically cropped from a real image. – REVOLUTION Aug 07 '19 at 12:22
  • See remap as per `fireant` solution below. – fmw42 Aug 07 '19 at 16:36

1 Answers1

2

The most generic solution is to use remap. See this answer on stackoverflow for a sample script that transform this image:

enter image description here

to this:

enter image description here

Those control points shown in red define the transformation. You'd set the first set of points on straight lines, and the destination points on curvy lines.

fireant
  • 14,080
  • 4
  • 39
  • 48