'Bug in ARCore acquireDepthImage?

The documentation states that it's 16 bits each with top 3 bits set to 0, meaning the range should be about 8,192. My code is calling

depthImage.getPlanes()[0].getBuffer().asShortBuffer().get(x)

The range of these numbers is about the full signed short range and seemingly random. To debug, I tried printing the following values:

depthImage.getPlanes()[0].getBuffer().get(0);
depthImage.getPlanes()[0].getBuffer().get(1);

The first one oscillates randomly and the second one is almost always in the low numbers such as 0-6, but I've seen as high as 21.

It seems like the 2nd byte is the most significant byte of the number and the 1st byte is the least significant byte (i.e. they are reversed).



Solution 1:[1]

It's little-endian encoding, use Short.reverseBytes():

depthMm = java.lang.Short.reverseBytes(depthImage.planes[0].buffer.getShort(offset))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1