I am new to OpenGL ES.
Currently working on Fisheye camera, able to display fisheye camera raw data on HDMI monitor using OPENGL ES rendering.
I could not find sample code to do fisheye image undistortion.
Can you please help me to provide sample code for image undistortion in shaders code.
I have attached a bit of code to do barrel distortion (this is used for VR). If you create a highly tessellated rectangle where to project your images, this code will move the vertices to distort the image. Play with the BarrelPower parameter until your distortion is corrected. The file is a PFX from where you should be able to extract the vertex and fragment shader. Hope this helps
Thank you for your reply.
I am looking Fish eye image undistortion.
The input of Fish eye image itself is distorted. We have to undistortion the fish eye image.
For eg: In Opencv “remap” function is used to undistrot the fish eye image.
Similar type of any API is there in OpenGL ES to do undistortion, if not Can you please provide some sample code how to do undistortion.
With the code I attached you can correct the distortion of the original (distorted) image. You might need to modify it to adapt it to your needs but it should work.
Hi Carlos,
The code which you sent it is for distortion.
In our case we have to do undistortion based on camera intrinsic parameters.
Please Find the attached input and output images.
The purpose of the code I sent you is different (it is for VR barrel distortion) so you need to modify it to fulfil your needs. I am surprised how well it works so probably it does not require many changes to convert it into a proper “unspherize” shader. This is something you will need to do yourself.
I am working on similar problem too (fish eye camera undistortion). Did you find a solution? If so, can you please share some sample code of your shader?
OpenGL ES cannot do magic. You have to use the vertex or the fragment shader to move the pixels to the right location. You need to work-out the algorithm yourself and pass the camera intrinsic parameters as uniforms. I gave you an example we used for barrel distortion for VR. Obviously this is not the same algorithm you might require in your case, but I suppose you can adapt it to your needs. Here you have an example that might help you.
The best solution I’ve found yet is to apply pincushion distortion from this shadertoy: https://www.shadertoy.com/view/4sXcDN
Only difference in my case was to delete this line:
6 vec2 source_uv = fragCoord.xy / iResolution.xy;
because my coords are already normalized.
Best params in my case are:
k1=-1.7 k2=1.7 scaleX=1.2 scaleY=1.2
Hi Ram & Carlos , I also need the code of fisheye distortion correction using vertex/fragment shader in openGL , if the code is implemented please share .
We do not have a full OpenGL example to show barrel distortion as it is a very trivial effect. It should work on any surface that is facing the user just applying any of the the fragments shaders supplied.
Maybe you will find this shadertoy link helpful. Shader - Shadertoy BETA You can modyfy this shader code to your needs, you might to change some variables, also delete some, as shadertoy variables are not supported in plain OpenGL. There might be also some shadertoy functions that are not available in pure GLSL.