Pointcloud到屏幕点

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

我想获得点云作为屏幕点。我将projectionMatrix和ViewMatrix相乘。然后将每个点分开处理。

我真的不知道我做错了什么。任何帮助?

 for (int i = 0; i < pointCloud.getPoints().remaining() / 4; i = i + 4) {
                    float x = pointCloud.getPoints().get(i);
                    float y = pointCloud.getPoints().get(i + 1);
                    float z = pointCloud.getPoints().get(i + 2);
                    float p = pointCloud.getPoints().get(i + 3);

                    float[] pointC = new float[]{x, y, z, 1.0F};
                    float[] screenPoint = new float[4];

                    float[] viewProjMtx = new float[16];
                    Matrix.multiplyMM(viewProjMtx, 0, projmtx, 0,viewmtx , 0);
                    Matrix.multiplyMV(screenPoint, 0,viewProjMtx , 0, pointC, 0);
                    float screenX = (result[0]+1)/2*1080;
                    float screenY = 2220-((result[1]+1)/2*2220);
                    String str = screenX+" "+screenY+"\r";
                }
android opengl-es arcore
1个回答
0
投票

我找到了合适的解决方案,或者至少我认为是。我将View Matrix与Projection Matrix相乘。获得的点在4X1矩阵中的结果。

我们得到一个4x1矩阵,必须用w除以得到透视投影。

为了获得归一化点,我们构建“变换屏幕”矩阵并相乘。

最后,只需使用宽度和高度,我们就可以将3Dpoint放入屏幕坐标。

 for (int i = 0; i < pointCloud.getPoints().remaining() ; i = i + 4) {
                        float x = pointCloud.getPoints().get(i);
                        float y = pointCloud.getPoints().get(i + 1);
                        float z = pointCloud.getPoints().get(i + 2);
                        float p = pointCloud.getPoints().get(i + 3);

                        float[] pointC = new float[]{x, y, z, 1.0F};
                        float[] res = new float[4];
                        float[] vpMatrix = new float[16];

                        Matrix.multiplyMM(vpMatrix, 0, projmtx, 0, viewmtx, 0);
                        Matrix.multiplyMV(res, 0, vpMatrix, 0, pointC, 0);

                        float[] mPp = new float[4];
                        mPp[0] = res[0] / res[3];
                        mPp[1] = res[1] / res[3];
                        mPp[2] = res[2] / res[3];
                        mPp[3] = 1;

                        float[] mVp = new float[16];
                        float[] ere = new float[4];

                        mVp[0] = 0.5f;
                        mVp[1] = 0;
                        mVp[2] = 0;
                        mVp[3] = 0;

                        mVp[4] = 0;
                        mVp[5] = -0.5f;
                        mVp[6] = 0;
                        mVp[7] = 0;

                        mVp[8] = 0;
                        mVp[9] = 0;
                        mVp[10] = 0.5f;
                        mVp[11] = 0;

                        mVp[12] = 0.5f;
                        mVp[13] = 0.5f;
                        mVp[14] = 0.5f;
                        mVp[15] = 1;
                        Matrix.multiplyMV(ere, 0, mVp, 0, mPp, 0);

                        float width = 1080;
                        float height = 1920;
                        float winX = ere[0] * width;
                        float winY = ere[1] * height;
                    }
© www.soinside.com 2019 - 2024. All rights reserved.