java - 将 Tango 3D 点投影到屏幕 Google Project Tango

标签 java projection google-project-tango projection-matrix

Ptoject Tango提供了点云,如何获取点云中3D点的像素位置(以米为单位)?

我尝试使用投影矩阵,但得到的值非常小(0.5、1.3 等),而不是 1234,324(以像素为单位)。

我包含了我尝试过的代码

    //Get the current rotation matrix
    Matrix4 projMatrix =  mRenderer.getCurrentCamera().getProjectionMatrix();



    //Get all the points in the pointcloud and store them as 3D points
    FloatBuffer pointsBuffer =  mPointCloudManager.updateAndGetLatestPointCloudRenderBuffer().floatBuffer;
    Vector3[] points3D = new Vector3[pointsBuffer.capacity()/3];

    int j =0;
    for (int i = 0; i < pointsBuffer.capacity() - 3; i = i + 3) {

        points3D[j]= new Vector3(
                pointsBuffer.get(i),
                pointsBuffer.get(i+1),
                pointsBuffer.get(i+2));
        //Log.v("Points3d", "J: "+ j + " X: " +points3D[j].x + "\tY: "+ points3D[j].y +"\tZ: "+ points3D[j].z );
        j++;
    }


    //Get the projection of the points in the screen.
    Vector3[] points2D = new Vector3[points3D.length];
    for(int i =0; i < points3D.length-1;i++)
    {
        Log.v("Points", "X: " +points3D[i].x + "\tY: "+ points3D[i].y +"\tZ: "+ points3D[i].z );
        points2D[i] = points3D[i].multiply(projMatrix);
        Log.v("Points", "pX: " +points2D[i].x + "\tpY: "+ points2D[i].y +"\tpZ: "+ points2D[i].z );
    }

我使用的示例是点云java,可以在这里找到 https://github.com/googlesamples/tango-examples-java

<小时/>

更新

TangoCameraIntrinsics ccIntrinsics = mTango.getCameraIntrinsics(TangoCameraIntrinsics.TANGO_CAMERA_COLOR);
    double fx = ccIntrinsics.fx;
    double fy = ccIntrinsics.fy;
    double cx = ccIntrinsics.cx;
    double cy = ccIntrinsics.cy;

    double[][] projMatrix = new double[][] {
            {fx, 0 , -cx},
            {0,  fy, -cy},
            {0,  0,    1}
    };

然后计算我使用的投影点

for(int i =0; i < points3D.length-1;i++)
    {

        double[][] point = new double[][] {
                {points3D[i].x},
                {points3D[i].y},
                {points3D[i].z}
        };

        double [][] point2d = CustomMatrix.multiplyByMatrix(projMatrix, point);

        points2D[i] = new Vector2(0,0);
        if(point2d[2][0]!=0)
        {
            Log.v("temp point", "pX: " +point2d[0][0]/point2d[2][0]+" pY: " +point2d[1][0]/point2d[2][0] );
            points2D[i] = new Vector2(point2d[0][0]/point2d[2][0],point2d[1][0]/point2d[2][0]);
        }

    }

但我认为结果仍然不是预期的,例如我得到的结果如下:

pX:-175.58042313027244 pY:-92.573740812066

在我看来,这看起来不对。

<小时/>

更新 按照建议使用彩色相机可以得到更好的结果,但分数仍然是负面的 -1127.8086915171814 pY:-652.5887102192332

将它们乘以-1可以吗?

最佳答案

您必须将 3D 点与 RGB 相机的内在矩阵相乘才能获得像素坐标。 3D 点位于 Depthcamera 的框架中。您可以通过以下方法获取像素坐标:

x 和 y 是像素坐标。 K 是使用 intrinsics 参数构造的功能

关于java - 将 Tango 3D 点投影到屏幕 Google Project Tango,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34565930/

相关文章:

java - 谷歌探戈/opencv Android 相机应用程序崩溃/挂起

java - 通过 Java 套接字错误传输文件

3d - 世界中给定 Z 的 2D 到 3D 投影

java - 在jpa中保存对象之前如何知道id

html - 修改属性 vec2 变量

javascript - d3 - 我可以以某种方式组成两个投影,或者投影一个投影吗?

java - Project Tango 开发环境 (java) 问题

java - 在Android中合并两个监听器的数据

java - 直接在线程对象上调用Runnable的run()方法

java - 使用 System.exit() 调用同一类中的另一个方法