需要帮助以适当的直线投影等矩形全景图像 [英] Need help for proper rectilinear projection of equirectangular panoramic image

查看:75
本文介绍了需要帮助以适当的直线投影等矩形全景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

With the algorithm below, when the projection plane is tangent to the equator (the center line of the equirectangular image), projected image looks rectilinear.

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

But when the projection plane is tilted, (py0 != panorama.height/2), lines are warped.

下面的算法中的最后两条线"需要校正",以便在目标平面的中心线与等角线的中心线不在同一水平线上时调整px和/或​​py图片.

The two last "lines" in the algorithm below needs to be "rectified", in order to adjust px and/or py when the center line of the destination plane is not at the same level than the center line of the equirectangular image.

  // 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代码将笛卡尔坐标转换为长/纬度:

I can compute the intersection p between the normal of each destination pixel and the sphere, then convert cartesian coordinates to long/lat using available C code:

但是我知道有一种更简单且耗时更少的方法,其中涉及在知道投影平面中心与投影机"中心相交的经度/纬度(px0,py0)的情况下,调整等边矩形图像(px,py)中的源像素坐标.球形".

But I know there's a simpler and much less time consuming method, involving adjusting source pixel coordinates in equirectangular image (px,py) knowing the longitude/latitude (px0,py0) at which the center of the projection plane intersect the "sphere".

可以帮忙吗?

推荐答案

我设法使用webgl着色器中的gnomonic投影公式使此方法起作用

I managed to get this to work using the formula for gnomonic projection in a webgl shader 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

这篇关于需要帮助以适当的直线投影等矩形全景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆