繁体   English   中英

ARCore:获取所有检测到的点的3D坐标

[英]ARCore: Get the 3D coordinates of all detected points

我正在用Java编写使用ARCore进行点云检测的应用程序。

我想获取所有点的3D坐标,这些坐标在框架中呈现。 如果使用以下代码,那么目前我仅能获得这些要点。

 pointCloud = frame.acquirePointCloud();
      if (list1 != null) {
      String x = String.valueOf(df.format(pointCloud.getPoints().get(0))).replace(",", ".");
      String y = String.valueOf(df.format(pointCloud.getPoints().get(1))).replace(",", ".");
      String z = String.valueOf(df.format(pointCloud.getPoints().get(2))).replace(",", ".");
      String c = String.valueOf(df.format(pointCloud.getPoints().get(3))).replace(",", ".");

      list1.add(x + ", " + y + ", " + z + ", " + c + "\n");
  }

我只找到了另一个实现。 我尝试过这一点,但是我得到了很多令人困惑的观点,这些观点逐渐消失了。

pointCloud = frame.acquirePointCloud();
if (list6 != null) {
    FloatBuffer fb = pointCloud.getPoints();
    while (fb.hasRemaining()) {
      float x = Float.parseFloat(df.format(fb.get()).replace(",", "."));
      float y = Float.parseFloat(df.format(fb.get()).replace(",", "."));
      float z = Float.parseFloat(df.format(fb.get()).replace(",", "."));
      float c = Float.parseFloat(df.format(fb.get()).replace(",", "."));

        list6.add(x + ", " + y + ", " + z + ", " + c + "\n");
    }
  }

我不确定这是代码中的问题。 某人是否有更好的主意来获取所有要点,或者可以告诉我我做错了什么?

我很乐意得到一些帮助。 谢谢。

我已使用此代码来获取点云数据。 您可以检查点云ID数组的长度,以了解点云的确切数量。

使用以下代码,您可以将点数据映射到确切的ID,并确保是否所有数据都可用。

    PointCloud pointCloud = frame.acquirePointCloud();
    IntBuffer pointCloudIds = pointCloud.getIds();
    int[] pointCloudIdsArray = new int[pointCloudIds.limit()];
    pointCloudIds.get(pointCloudIdsArray);

    Log.i(TAG, "onDrawFrame: Point Cloud Id Array Length " + 
    pointCloudIdsArray.length);

    FloatBuffer pointCloudData = pointCloud.getPoints();

    float[] pointCloudArray = new float[pointCloudData.limit()];
    pointCloudData.get(pointCloudArray);

    Log.i(TAG, "onDrawFrame: Point Cloud Data Array Length " + pointCloudArray.length);

    long PointCloudTimeStamp = pointCloud.getTimestamp();

    if (pointCloudIdsArray.length > 0) {
        for (int i = 0; i < pointCloudIdsArray.length; i++) {

            Log.i("TAG",Long.toString(PointCloudTimeStamp) + ";" +
            Integer.toString(pointCloudIdsArray[i]) + ";" +
            Float.toString(pointCloudArray[i * 4]) + ";" +
            Float.toString(pointCloudArray[i * 4 + 1]) + ";" +
            Float.toString(pointCloudArray[i * 4 + 2]) + ";" +
            Float.toString(pointCloudArray[i * 4 + 3]) + "\n");
        }

    } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM