Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL Image warping using lookup table

I am working on an Android application that slims or fatten faces by detecting it. Currently, I have achieved that by using the Thin-plate spline algorithm. http://ipwithopencv.blogspot.com.tr/2010/01/thin-plate-spline-example.html

The problem is that the algorithm is not fast enough for me so I decided to change it to OpenGL. After some research, I see that the lookup table texture is the best option for this. I have a set of control points for source image and new positions of them for warp effect. How should I create lookup table texture to get warp effect?

like image 494
sedatli Avatar asked Oct 24 '17 08:10

sedatli


1 Answers

Are you really sure you need a lookup texture?

Seems that it`d be better if you had a textured rectangular mesh (or a non-rectangular mesh, of course, as the face detection algorithm you have most likely returns a face-like mesh) and warped it according to the algorithm:

enter image description here

Not only you`d be able to do that in a vertex shader, thus processing each mesh node in parallel, but also it`s less values to process compared to dynamic texture generation.

The most compatible method to achieve that is to give each mesh point a Y coordinate of 0 and X coordinate where the mesh index would be stored, and then pass a texture (maybe even a buffer texture if target devices support it) to the vertex shader, where at the needed index the R and G channels contain the desired X and Y coordinates.

Inside the vertex shader, the coordinates are to be loaded from the texture.

This approach allows for dynamic warping without reloading geometry, if the target data texture is properly updated — for example, inside a pixel shader.

like image 141
hidefromkgb Avatar answered Oct 22 '22 00:10

hidefromkgb