我正在使用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");
}
}
我不确定代码中是否存在问题。 某人是否有更好的主意来获得所有要点,或者可以告诉我我做错了什么?
我会很高兴获得一些帮助。谢谢。
答案 0 :(得分:0)
我已使用此代码获取点云数据。您可以检查点云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");
}
}