我必须将其打印floatbuffer
为,array
并且在文档中有针对该功能的功能,但是该功能无法正常工作。我不明白我在做什么错?
我尝试使用,floatBuffer.toString()
但它确实打印array
了document(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
根据documentation(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);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句