Fish eye camera image undistortion using OpenGL ES

Hi,

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.

Thanks,
Ram.

Hi Ram,

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 :slight_smile:

Regards

Carlos.
barrel.zip (897 Bytes)

Hi Carlos,

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.

Thanks,
Ram.

Hi Ram,

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.

Regards.

Carlos.

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.

Please let me know your comments.

Thanks,
Ram.

Hi Ram,

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.

Best regards.

Carlos.

Hi Ram,

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?

Thanks,
Artem.

Hi Artem,

Still we could not find solution, how to do fisheye camera undistortion in OPENGL ES.

@CarlosSarria
I have few questions regarding undistortion

  1. I believe Camera intrinsic parameters are required to do undistortion, Is this correct?
  2. If Yes, How to give these parameters in OPENGL ES for undistortion fisheye image?

Thanks,
Ram.

Hi Artem,

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.

Regards.

Carlos.

Hi Carlos,

Thanks for your reply. I will do my best to create an algorithm by myself.

Regards,
Artem.

Hi Artem,

Did you find a solution for fish eye camera undistortion?

Thanks,
Ram.

Hi Ram,

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

BR,
Artem

Default image:

Hi sir, I also want this code if found please share the code.

Best Regards,
Bharathi

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 .

BR,
Bharathi

Hi, Bharathi.

You can find the code attached above and also in the shadertoy snippet Artem pointed to. Do you need anything beyond this?

Best regards.

Carlos.

Thanks for the reply sir , I need the code for fisheye correction in openGL using vertex/fragment shader sir .

Hi, Bharati.

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.

Regards.

Carlos.

Hi Ram,
I’m dealing with exactly the same problem, do you have any suggestions?

Hi magnet1c,

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.

Best Reagards,
Tytus.