0

There is a useful function in scikit-image: the PiecewiseAffineTransform, It is provided by the python package of scikit-image which cannot be used in c++ like opencv, how could I implement similar function of it with opencv or python package cv2?

The usage of that function can be found in this link: https://scikit-image.org/docs/dev/auto_examples/transform/plot_piecewise_affine.html

CoinCheung
  • 85
  • 10
  • 1
    Just wondering, why do you want to use `cv2` if you could use `skimage`? – jkr May 14 '20 at 02:18
  • You would have to create a triangular mesh of control points. Then loop over each triangle and warp it using cv2.warpAffine(). – fmw42 May 14 '20 at 02:59
  • @jakub because I can translate cv2 to opencv in c++ when I know how to do it with cv2, but I cannot use skimage in the c++ code. – CoinCheung May 14 '20 at 03:02
  • @fmw42 Thanks for replying, would you be more specific? How could I create the triangular mesh, could I still keep the image look continuous in this way? – CoinCheung May 14 '20 at 03:04
  • 1
    It would be continuous if you use barycentric interpolation for texture mapping between triangles. See https://codeplea.com/triangular-interpolation and https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/barycentric-coordinates. But I have no idea how to get your triangular mesh without Delauney triangulation from Skimage. I do not know of any equivalent in OpenCV other than manually picking points with some GUI. See https://dahtah.wordpress.com/2013/03/06/barycentric-interpolation-fast-interpolation-on-arbitrary-grids/ – fmw42 May 14 '20 at 06:18
  • I have a very simple example in ImageMagick where the points are picked manually and triangles created. See http://www.fmwconcepts.com/imagemagick/meshwarp/index.php – fmw42 May 14 '20 at 06:19
  • [qhull](https://github.com/qhull/qhull/wiki) can be used for Delauney triangulation in c++ (that's actually what skimage uses under the hood) – Mark Loyman Nov 24 '22 at 06:17

0 Answers0