3d - 需要帮助正确直线投影等距柱状全景图像

标签 3d trigonometry panoramas projective-geometry

使用下面的算法,当投影平面与赤道(等距柱状图的中心线)相切时,投影图像看起来是直线的。

Rectilinear image

但是当投影平面倾斜时,(py0 != panorama.height/2),线条会扭曲。

Warped image

下面算法中的最后两条“线”需要“修正”,以便在目标平面的中心线与等距柱状图的中心线不在同一水平线上时调整 px 和/或 py。

  // u,v,w :
  //     Normalized 3D coordinates of the destination pixel

  // elevation, azimuth:
  //     Angles between the origin (sphere center) and the destination pixel

  // px0, py0 :
  //     2D coordinates in the equirectangular image for the
  //     the destination plane center (long*scale,lat*scale)

  // px, py:
  //     2D coordinates of the source pixel in the equirectangular image
  //     (long*scale,lat*scale)

  angularStep=2*PI/panorama.width;
  elevation=asin(v/sqrt(u*u+v*v+w*w));
  azimuth=-PI/2+atan2(w,u);
  px=px0+azimuth/angularStep;
  py=py0+elevation/angularStep;

我可以计算每个目标像素的法线与球体之间的交集 p,然后使用可用的 C 代码将笛卡尔坐标转换为长/纬度:

projection

但我知道有一种更简单且耗时更少的方法,包括在知道投影平面中心与“球体”相交的经度/纬度 (px0,py0) 的等距柱状投影图像 (px,py) 中调整源像素坐标。

你能帮忙吗?

最佳答案

我设法使用 webgl 着色器中的 gnomonic 投影公式使这个工作http://mathworld.wolfram.com/GnomonicProjection.html

            float angleOfView   

            float phi1          
            float lambda0     //centre of output projection

            float x = PI2*(vTextureCoord.s - 0.5) ;  //input texture coordinates, 
            float y = PI2*(vTextureCoord.t - 0.5 ); 

            float p = sqrt(x*x + y*y);

            float c = atan(p, angleOfView); 

            float phi = asin( cos(c)*sin(phi1) + y*sin(c)*cos(phi1)/p );

            float lambda = lambda0 + atan( x*sin(c), (p*cos(phi1)*cos(c) - y*sin(phi1)*sin(c)));

            vec2 tc = vec2((lambda /(PI*2.0) + 0.5, (phi/PI) + 0.5); //reprojected texture coordinates 

            vec4 texSample  =  texture2D(tEqui, tc); //sample using new coordinates

关于3d - 需要帮助正确直线投影等距柱状全景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22003467/

相关文章:

c++ - 如何计算法 vector ?

javascript - 如何通过给定的 2 个点计算弧的 'start' 和 'end' Angular ?

Python 正弦和余弦给出错误的值

python - 将两张图像混合成全景图

actionscript - 谷歌地图如何制作全景图?

java - libGDX:更改 3d 模型的可见性

3d - 单位球面上的均匀随机 (Monte-Carlo) 分布

c++ - 计算直线上点的投影的优化函数?

math - 围绕原点进行 3d 旋转

javascript - Three.js:在全景图的地板上添加图像