我必须打印这个floatbuffer
作为array
并且在文档中有一个功能,但功能不起作用。我不明白我做错了什么?
我曾尝试使用floatBuffer.toString()
,但它确实打印了文档(array
)所描述的ARCore
。这不是正确的结果。
Camera camera = frame.getCamera();
CameraIntrinsics cameraIntrinsics=camera.getImageIntrinsics();
float[] focal=cameraIntrinsics.getFocalLength();
Log.e("Focals",Arrays.toString(focal));
int [] getDiminsions=cameraIntrinsics.getImageDimensions();
Log.e("Dimensions ", Arrays.toString(getDiminsions));
backgroundRenderer.draw(frame);
PointCloud pointCloud=frame.acquirePointCloud();
FloatBuffer floatBuffer=pointCloud.getPoints();
FloatBuffer readonly=floatBuffer.asReadOnlyBuffer();
//final boolean res=readonly.hasArray();
final float[] points=floatBuffer.array();
//what should I do
根据文档(ARCore
),floatBuffer
中的每个点都有4个值:x,y,z坐标和置信度值。
根据FloatBuffer的实现,如果缓冲区没有数组支持,则array()
方法可能不可用。如果您要做的只是遍历值,则可能不需要数组。
FloatBuffer floatBuffer = pointCloud.getPoints();
// Point cloud data is 4 floats per feature, {x,y,z,confidence}
for (int i = 0; i < floatBuffer.limit() / 4; i++) {
// feature point
float x = floatBuffer.get(i * 4);
float y = floatBuffer.get(i * 4 + 1);
float z = floatBuffer.get(i * 4 + 2);
float confidence = floatBuffer.get(i * 4 + 3);
// Do something with the the point cloud feature....
}
但是如果你确实需要使用一个数组,你需要调用hasArray()
,如果没有,则分配一个数组并复制数据。
FloatBuffer floatBuffer = pointCloud.getPoints().asReadOnlyBuffer();
float[] points;
if (floatBuffer.hasArray()) {
// Access the array backing the FloatBuffer
points = floatBuffer.array();
} else {
// allocate array and copy.
points = new float[floatBuffer.limit()];
floatBuffer.get(points);
}