1

I'm trying to write a program that's able to perform something like this

enter image description here

Or in short, let user specify the point of transformation on the image and able to drag to create a warp transformation. So far, I tried to play around with remap in opencv, but I could only do perspective transformation but not mesh. I also noticed the function 'undistort' which seem to look like what I'm looking but I'm not too sure. Any advice on how I move forward with this (function recommendation/ open source recommendation) would be highly appreciate! Also, if you have a recommendation on how to do this that's in web app development/ OS, android app development, I'd highly appreciate that too!

PS: I also found this open source https://github.com/cxcxcxcx/imgwarp-opencv which seem to perform something similar to what I'm trying to do but it's in C++ which I don't exactly know the language.

Philipp H.
  • 1,513
  • 3
  • 17
  • 31
  • Does this answer your question? [Image transformation in OpenCV](https://stackoverflow.com/questions/10364201/image-transformation-in-opencv) – Philipp H. Jun 09 '20 at 16:18
  • I do not think there is any OpenCV method to do that. But you can process each grid cell using a perspective transformation or break each cell into 2 triangles and use an affine transformation. – fmw42 Jun 09 '20 at 18:11
  • look at https://scikit-image.org/docs/dev/auto_examples/transform/plot_piecewise_affine.html#sphx-glr-auto-examples-transform-plot-piecewise-affine-py – Amitay Nachmani Jun 09 '20 at 19:22
  • @fmw42 can you explain more on what do you mean breaking each cell into 2 triangles and use affline transformation? Would that be generating the result I'm looking for? – peanutbutter2000 Jun 11 '20 at 05:02
  • @PhilippH. I'm trying to work on using the remap method (which seem like the link u have r using it). I tried to do it with barycentric coordinate but seem like there's a problem with run time for that method according to this post https://stackoverflow.com/questions/31442826/increasing-efficiency-of-barycentric-coordinate-calculation-in-python . Any advice on how to move forward? – peanutbutter2000 Jun 11 '20 at 05:04
  • @AmitayNachmani that seem to only able to do a cos and sine function but not custom one. Can we also do a more custom one where user can warp any part they want? – peanutbutter2000 Jun 11 '20 at 05:06
  • @peanutbutter2000 You can do wherever you want. The example shows that they manipulated the points using cos or sin function but you can choose to move each point to where you want. – Amitay Nachmani Jun 11 '20 at 05:18
  • `@peanutbutter2000`. You simply divide the rectangle into two triangle by drawing a line along one of the diagonals. Then for each triangle, you use barycentric coordinates to transform between input and output triangles. Look up Barycentric coordinates, for example, https://en.wikipedia.org/wiki/Barycentric_coordinate_system. What you want to do needs splines. But you can approximate your grid with quadrilaterals or split the quadrilaterals into triangles. – fmw42 Jun 11 '20 at 06:11
  • @peanutbutter2000 you can calculate a downsampled map and then scale it up to the original image size. The map is usually very smooth locally, therefore using a 8 to 32 downsampled version should be fine. – Philipp H. Jun 11 '20 at 08:24

0 Answers0