小编Bun*_*ing的帖子

使用gpu着色器bug进行失真校正

所以我有一台带广角镜头的相机.我知道失真系数,焦距,光学中心.我想要反映我从这台相机获得的图像.我第一次尝试使用OpenCV(cv :: undistort),效果很好,但速度太慢了.

现在我想在gpu上做这个.有一个着色器正是在http://willsteptoe.com/post/67401705548/ar-rift-aligning-tracking-and-video-spaces-part-5中记录了这一点.

公式可以在这里看到:http: //en.wikipedia.org/wiki/Distortion_%28optics%29#Software_correction

所以我去实现了我自己的版本作为glsl着色器.我发送一个四边形纹理坐标在0..1之间的角落.我假设到达的纹理坐标是未失真图像的坐标.我计算与我的纹理坐标对应的扭曲点的坐标.然后我对失真的图像纹理进行采样.

使用此着色器在最终图像中没有任何变化.我通过cpu实现确定的问题是,系数项非常接近于零.通过半径平方等数字变得越来越小.所以我有一个缩放问题 - 我无法弄明白该做什么不同!我尝试了所有的东西......我想这是非常明显的事情,因为这种过程似乎适用于很多人.

为简单起见,我省略了切向失真校正.

#version 330 core

in vec2 UV;

out vec4 color;

uniform sampler2D textureSampler;

void main()
{   
    vec2 focalLength = vec2(438.568f, 437.699f);
    vec2 opticalCenter = vec2(667.724f, 500.059f);
    vec4 distortionCoefficients = vec4(-0.035109f, -0.002393f, 0.000335f, -0.000449f);

    const vec2 imageSize = vec2(1280.f, 960.f);

    vec2 opticalCenterUV = opticalCenter / imageSize;

    vec2 shiftedUVCoordinates = (UV - opticalCenterUV);

    vec2 lensCoordinates = shiftedUVCoordinates / focalLength;

    float radiusSquared = sqrt(dot(lensCoordinates, lensCoordinates));
    float …
Run Code Online (Sandbox Code Playgroud)

opengl shader gpu glsl distortion

2
推荐指数
1
解决办法
3685
查看次数

标签 统计

distortion ×1

glsl ×1

gpu ×1

opengl ×1

shader ×1