Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGL lens distortion reversal applied unequally to x and y, only works on square images #3

Closed
jywarren opened this issue Jan 11, 2017 · 6 comments

Comments

@jywarren
Copy link
Owner

jywarren commented Jan 11, 2017

Problem

The distortion only works properly for square images -- if the height and width are different, it doesn't correctly remove the lens distortion.

We need to account for the dimensions of the image. #2 links to another project which does this properly. Note that in the fragment shader, field of view is present, but never used:

https://github.com/jywarren/fisheyegl/blob/master/shaders/fragment.glfs#L21-L23

	float L = length(vec3(vPosition.xy/scale, F));

	vec2 vMapping = vPosition.xy * F / L;

F should be applied differently vertically and horizontally, or something. (guessing here)

Theory: maybe the image is "clamped" to the edges of a square WebGL buffer before being distorted, so any non-square image is smushed before being distorted. This actually makes a bit more sense to me but I'm not sure it's what's going on.

In any case, until we can apply F differently for x vs. y, we won't be able to correctly undistort images.

Possible solutions

I believe the key is "length" calculated on this line, but am not sure: https://github.com/jywarren/fisheyegl/blob/master/shaders/fragment.glfs#L21

I think it might also work to not cover the entire square WebGL working area, and to crop out "letterboxing" after WebGL's done it's work.

@jywarren jywarren added the bug label Jan 11, 2017
@jywarren
Copy link
Owner Author

I've added some more detail, test images, and discussion over at https://publiclab.org/notes/warren/12-30-2016/web-based-fisheye-removal-prototype-for-correcting-lens-distortion

We'd love help from anyone with some WebGL experience!

@jywarren jywarren changed the title Distortion applied unequally to x and y WebGL lens distortion reversal applied unequally to x and y, only works on square images Jun 26, 2017
@jywarren
Copy link
Owner Author

@Azorlogh
Copy link
Contributor

I tried my best to fix it with a modified algorithm for the different x and y corrections.
#5

@jywarren
Copy link
Owner Author

YES! It's fixed. This is perfect. Thank you.

distortion-fixed

@jywarren
Copy link
Owner Author

I think you have to mark it complete before I can award the bounty?

@jywarren
Copy link
Owner Author

Also if you'd like to link to this solution (#5) from StackOverflow I can mark your answer accepted there too!

https://stackoverflow.com/questions/45110817/webgl-lens-distortion-reversal-applied-unequally-to-x-and-y-only-works-on-squar?noredirect=1#comment77194226_45110817

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants