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

port over to OpenCV? #28

Open
oneshell opened this issue Sep 12, 2019 · 2 comments
Open

port over to OpenCV? #28

oneshell opened this issue Sep 12, 2019 · 2 comments

Comments

@oneshell
Copy link

The live demo is fantastic, thanks for making this available.

I am trying to understand the math/algorithm going on behind the scenes. I want to calibrate a Raspberry Pi wide FOV camera using your approach, then use these lens parameters in an OpenCV loop to dewarp a video stream.

Your live demo does everything I want in terms of finding the parameters, now I'm struggling with how to apply this to a video feed in OpenCV.

Could you point me in the right direction?

Thanks,

@jywarren
Copy link
Owner

Hi, @oneshell - sorry, saw your email but was a bit busy yesterday. Glad to answer here!

The issue is that we are doing this via WebGL, so the conversion is done via a shader. We feed the variables in here:

fisheyegl/src/fisheyegl.js

Lines 257 to 259 in 89d28f0

gl.uniform3fv(uLensS, [lens.a, lens.b, lens.scale]);
gl.uniform2fv(uLensF, [lens.Fx, lens.Fy]);
gl.uniform2fv(uFov, [fov.x, fov.y]);

These are applied in the shaders:

float scale = uLens.w;\n\
float F = uLens.z;\n\
\n\
float L = length(vec3(vPosition.xy/scale, F));\n\
vec2 vMapping = vPosition.xy * F / L;\n\
vMapping = vMapping * uLens.xy;\n\
vMapping = GLCoord2TextureCoord(vMapping/scale);\n\
vec4 texture = texture2D(uSampler, vMapping);\n\
if(vMapping.x > 0.99 || vMapping.x < 0.01 || vMapping.y > 0.99 || vMapping.y < 0.01){\n\
texture = vec4(0.0, 0.0, 0.0, 1.0);\n\
} \n\
gl_FragColor = texture;\n\

However, I believe they are determining the geometry of a GL surface, rather than doing this per pixel (in a GL paradigm rather than a pixel mapper). GL isn't my strong suit, and I am not very familiar with OpenCV, but here are some resources that may help you use the parameters in OpenCV:

I'm not sure if they use the same model, but perhaps there is some way to convert and use the parameters in whatever model they are using?

Sorry I'm not more helpful!

@guilhermecgs
Copy link

same problem here...

I would love to have a port to open-cv

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

No branches or pull requests

3 participants