OpenGL shader环视鱼眼相机图像变换问题

问题描述 投票:0回答:0

我正在尝试使用 OpenGL 重新实现这个环绕视图项目: https://github.com/neozhaoliang/surround-view-system-introduction/blob/master/doc/zh.md.

我正在尝试在片段着色器中实现这两个功能。

enter image description here

enter image description here

然而,结果是错误的

这是我的片段着色器代码:

#version 330 core
out vec4 fragColor;

uniform sampler2D testTexture;

mat3 projectMatrix = mat3(
    -1.5134401274988541e+01,    -6.7381376780590163e-01,    4.9428170463677217e-04,
    -4.2169445692489937e+01,    -2.9044610322524363e+01,    -4.7489470989931934e-02,
    1.0724381138361938e+04,     4.1490641432000384e+03,     1.0
);

float kf[] = {
    1.0, 
    -3.5510560636666778e-02, 
    -1.9848228876245811e-02, 
    2.6080053057044101e-02, 
    -9.7183762742328750e-03
};
    
void main() {
    mat3 qf = mat3(gl_FragCoord.x, gl_FragCoord.y, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
    mat3 pu = projectMatrix * qf;
    float pux = float(pu[0][0]) / float(pu[0][2]);
    float puy = float(pu[0][1]) / float(pu[0][2]);
    float ru = pow(pow(pux,2.0) + pow(puy,2.0), 0.5);
    float dg = atan(ru);
    float rd = kf[0]*dg + kf[1]*pow(dg,3) + kf[2]*pow(dg,5) + kf[3]*pow(dg,7) + kf[4]*pow(dg,9);
    vec2 pd = (rd/ru) * vec2(pux, puy);
    fragColor = texture(testTexture, pd); 
}

我是OpenGL和C++的新手,请告诉我哪里做错了

我正在尝试生成这样的校准图像:

enter image description here

c++ opengl shader camera-calibration fisheye
© www.soinside.com 2019 - 2024. All rights reserved.