如何找到正确的图像和像素以复制到等矩形/ 360全景画布中

如何解决如何找到正确的图像和像素以复制到等矩形/ 360全景画布中

我正在尝试找出如何在等边矩形画布(水平360°和垂直180°)上获取像素位置(x,y),并找到与该等边矩形画布上的确切位置匹配的对应图像和像素。找到匹配项后,我们只需将图像中正确的像素(颜色)复制到等矩形画布上即可。

但是我目前的问题是找出什么图像看到与等角画布上的像素位置(x,y)相对应的位置,并找到要复制的正确像素。这个想法是制作一个可以将图像拼接在一起的完整360度等角矩形图像的贴纸。等矩形画布的尺寸为4096 x 2048。

因此,要弄清楚这个想法是在等角画布中循环遍历每个像素,并计算其在球面或圆柱/地理坐标系中的位置

我们像这样遍历像素。

   for (int i = 0; i < EquirectangularCanvas.size().height; i++)
    {
        for (int j = 0; j < EquirectangularCanvas.size().width; j++)
        {

然后,我们很可能必须将其转换为笛卡尔坐标,并比较/减去图像上的信息,直到找到具有与矩形矩形像素位置相对应的可见点的正确图像为止。我们在图像上拥有的信息如下。

示例图片:

尺寸1280 x 720像素。

水平视角为92°,垂直视角为45°。

图像是在45度偏航和45度俯仰下拍摄的。

Image example

由于图像是在游戏内部捕获的,因此图像的FOV和位置将具有100%的准确性。所以位置永远是100%

Equirectangular canvas example

我希望至少在数学方面,我能在正确的方向上获得一些帮助。最终的目标不是使用C ++使用Opencv或类似的方法来进行像素位置移动等。我这样做是因为我想学习,而且我认为这是一个非常有趣且具有挑战性的项目。关于将图像放置在等角矩形画布中,我在互联网上找不到太多相关信息。但是,有很多关于在不同投影之间进行转换的信息,而不是真正关于将图像转换成等矩形投影的信息。

基本上,这就是我在这方面走了多远。我使自己成为一个小程序,可以帮助我测试一些代码。它打印出与等角矩形画布上鼠标位置相对应的一些信息。我的计划是首先找到一种方法来检查图像是否在鼠标所在的位置拍摄。比返回true。下一步是将正确的位置从图像准确复制到等矩形画布。 代码正在使用OpenCV。希望我能在这里得到一些帮助。

#define RadiansToDegrees(angleRadians) ((angleRadians) * 180.0 / M_PI)
#define RAD(x) M_PI*(x)/180.0
static void OnMouseMove(int event,int x,int y,int,void*)
{
    Mat EquirectangularCanvas(2048,4096,CV_8UC3,Scalar(0,0));//Equirectangular Canvas 180 degrees,360 degrees
    
    Vec3b color(0,255,0);
    line(EquirectangularCanvas,Point(0,EquirectangularCanvas.size().height / 2),Point(EquirectangularCanvas.size().width,color,2);//Draw Line In Center For Referanse
    line(EquirectangularCanvas,Point(EquirectangularCanvas.size().width / 2,0),EquirectangularCanvas.size().height),2);//Draw Line In Center For Referanse
    
    ostringstream MouseString;
    MouseString << "Mouse Position(X:" << x << ",Y:" << y << ");";
    putText(EquirectangularCanvas,MouseString.str(),25),FONT_HERSHEY_SIMPLEX,1,2,LINE_AA);//Draw Mouse Pixel Position

    float Phi = M_PI * y / EquirectangularCanvas.size().height;//This will position midpoints in the image along the y-axis in the sphere
    float Theta = 2 * M_PI * x / EquirectangularCanvas.size().width;//This will position midpoints in the image along the x-axis in the sphere

    //Don't know if it is better centering the midpoint. It can be done like this. But than i can't figure out getting the right pixel location when converting from cartesian to spherical.
    //float Phi = M_PI * (y - (EquirectangularCanvas.size().height / 2)) / EquirectangularCanvas.size().height;//This will position midpoints in the center of the image.
    //float Theta = 2 * M_PI * (x - (EquirectangularCanvas.size().width / 2)) / EquirectangularCanvas.size().width;//This will position midpoints in the center of the image.

    ostringstream SphericalCoordinates;
    ostringstream SphericalCoordinatesInDegrees;
    SphericalCoordinates << "Spherical Coordinates(X/Theta/Longitude:" << Theta << ",Y/Phi/Latitude:" << Phi << ");";
    SphericalCoordinatesInDegrees << "Spherical Coordinates In Degrees(X:" << RadiansToDegrees(Theta) << ",Y:" << RadiansToDegrees(Phi) << ");";
    putText(EquirectangularCanvas,SphericalCoordinates.str(),55),LINE_AA);
    putText(EquirectangularCanvas,SphericalCoordinatesInDegrees.str(),55 + 30),LINE_AA);

    Vec3d vec_cartesian;//Convert Spherical To Cartesian
    vec_cartesian[0] = sin(Phi) * cos(Theta);
    vec_cartesian[1] = sin(Phi) * sin(Theta);
    vec_cartesian[2] = cos(Phi);

    ostringstream Cartesian;
    Cartesian << "Rectangular/Cartesian(X:" << vec_cartesian[0] << ",Y:" << vec_cartesian[1] << ",Z:" << vec_cartesian[2] << ");";
    putText(EquirectangularCanvas,Cartesian.str(),85 + 30),LINE_AA);//Draw Cartesian Coordinates

    //Here is the part i am stuck at.
    //We have the theta and phi corresponding to a pixel in an equirectangular projection.
    //We than need to find the point in one of the images(We have in this case one image as describes above,for testing purposes) corresponding to that pixel in the equirectangular canvas.
    //equirectangular canvas xy -> Images xy -> place color from image xy in equirectangular canvas xy
    
    //I use mouse position in this case for easier testing and understanding. But when i get the math right it is going to get coded into a loop that loops over all the pixel in the equirectangular canvas.
    //Like this..
    /*for (int i = 0; i < (EquirectangularCanvas.size().height; i++)
    {
        for (int j = 0; j < EquirectangularCanvas.size().width; j++)
        {
    */

    //So what i think i need to do first is checking if image is outside fov. 
    //Then calculate how far away it is from center of that image and calculate to get the exact pixel to copy the color from..
    
    
    /*Maybe Some useful math -->*/
// XYZ-eular rotation https://github.com/whdlgp/Equirectangular_rotate
//Mat eular2rot(Vec3d theta)
//{
//  // Calculate rotation about x axis
//  Mat R_x = (Mat_<double>(3,3) <<
//      1,//      0,cos(theta[0]),-sin(theta[0]),sin(theta[0]),cos(theta[0])
//      );
//
//  // Calculate rotation about y axis
//  Mat R_y = (Mat_<double>(3,3) <<
//      cos(theta[1]),sin(theta[1]),//      -sin(theta[1]),cos(theta[1])
//      );
//
//  // Calculate rotation about z axis
//  Mat R_z = (Mat_<double>(3,3) <<
//      cos(theta[2]),-sin(theta[2]),//      sin(theta[2]),cos(theta[2]),1);
//
//  // Combined rotation matrix
//  Mat R = R_x * R_y * R_z;
//
//  return R;
//}

    Vec2d vec_rot;//CONVERSION FROM CARTESIAN TO SPHERICAL
    vec_rot[0] = acos(vec_cartesian[2]);//phi //latitude
    vec_rot[1] = atan2(vec_cartesian[1],vec_cartesian[0]);//theta //longitude
    

    ostringstream RETURNEDSPHERICALCOORDS;
    RETURNEDSPHERICALCOORDS << "RETURNED SPHERICAL COORDS(X:" << vec_rot[1] << ",Y:" << vec_rot[0] << ");";
    putText(EquirectangularCanvas,RETURNEDSPHERICALCOORDS.str(),115 + 30),LINE_AA);


    Vec2i vec_pixel;
    vec_pixel[0] = EquirectangularCanvas.size().height * vec_rot[0] / M_PI;
    vec_pixel[1] = EquirectangularCanvas.size().width * vec_rot[1] / (2 * M_PI);

    ostringstream PixelCoordToFind;
    PixelCoordToFind << "Pixel Coord For RETURNED SPHERICAL COORDS(X:" << vec_pixel[1] << ",Y:" << vec_pixel[0] << ");";
    putText(EquirectangularCanvas,PixelCoordToFind.str(),145 + 30),LINE_AA);
    /*<-- Maybe Some useful math*/

    imshow("Equirectangular Canvas",EquirectangularCanvas);
}

int main()
{
    namedWindow("Equirectangular Canvas",WINDOW_AUTOSIZE);
    setMouseCallback("Equirectangular Canvas",OnMouseMove);
    
    waitKey(0);
    destroyAllWindows();
    
    return 1;

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-