Depth
interface Depth extends HybridObjectA Depth Frame is a frame
captured from a CameraDepthFrameOutput.
It contains depth data which can
be accessed via native plugins,
or from JS using getDepthData().
The depth's format (pixelFormat)
specifies the returned ArrayBuffer's format.
Depth data has to be disposed (see dispose())
to free up the memory, otherwise the producing pipeline
might stall.
Properties
availableDepthPixelFormats
readonly availableDepthPixelFormats: DepthPixelFormat[]Gets the list of DepthPixelFormats this
Depth can be converted to using convert(...).
Note
If this Depth is invalid (isValid), this returns an empty array ([]).
Note
Some platforms may return an empty array ([]) if conversion is not supported.
bytesPerRow
readonly bytesPerRow: numberGet the number of bytes per row of the underlying pixel buffer.
This may return 0 if the Depth
is planar.
See
cameraCalibrationData?
readonly optional cameraCalibrationData: CameraCalibrationDataGets the associated CameraCalibrationData for this
Depth, if available.
Camera calibration data can be used to project depth values into camera/world coordinates with higher accuracy.
depthDataAccuracy
readonly depthDataAccuracy: DepthDataAccuracyGets the measurement accuracy of this Depth.
'absolute': The depth values represent absolute distances.'relative': The depth values represent relative distances.'unknown': Accuracy is unknown or unavailable.
depthDataQuality
readonly depthDataQuality: DepthDataQualityGets the quality classification of this Depth.
'high': High quality depth data.'low': Lower quality depth data.'unknown': Quality is unknown or unavailable.
height
readonly height: numberGets the total height of this Depth.
Note
If this Depth is invalid (isValid), this may return 0.
isDepthDataFiltered
readonly isDepthDataFiltered: booleanGets whether the depth map has been filtered/smoothed by the platform.
Filtering typically reduces noise and smoothens out uneven spots in the depth map at the cost of some fine detail.
Note
If this metadata is unavailable for this Depth, this may be false.
isMirrored
readonly isMirrored: booleanGets whether this Depth frame is mirrored alongside the
vertical axis.
isValid
readonly isValid: booleanGets whether this Depth is still valid, or not.
If the Depth is invalid, you cannot access its data anymore.
A Depth is automatically invalidated via dispose().
orientation
readonly orientation: OrientationThe rotation of this Depth relative to the
associated CameraDepthFrameOutput's target output orientation.
Depth data is not automatically rotated to 'up' because physically
rotating buffers is expensive. The Camera streams depth frames in the
hardware's native orientation and adjusts presentation later using
metadata, transforms, or here; a flag.
Discussion
If you process this Depth, you must interpret
its pixel data to be rotated by this orientation.
pixelFormat
readonly pixelFormat: DepthPixelFormatGets the DepthPixelFormat of this Depth Frame's
pixel data.
Common formats are 'depth-16-bit'
for depth frames, or 'disparity-16-bit'
for disparity frames.
timestamp
readonly timestamp: numberGets the presentation timestamp this Depth was timed at.
Note
If this Depth is invalid (isValid), this may return 0.
width
readonly width: numberGets the total width of this Depth.
Note
If this Depth is invalid (isValid), this may return 0.
Methods
convert()
convert(pixelFormat: DepthPixelFormat): DepthConverts this Depth frame to the target pixelFormat.
The pixelFormat must be one of the DepthPixelFormats
returned from availableDepthPixelFormats.
convertAsync()
convertAsync(pixelFormat: DepthPixelFormat): Promise<Depth>Asynchronously converts this Depth frame to the target pixelFormat.
The pixelFormat must be one of the DepthPixelFormats
returned from availableDepthPixelFormats.
convertCameraPointToDepthPoint()
Converts the given cameraPoint in
camera sensor coordinates into a Point
in Depth coordinates, relative to this Depth.
Note
Camera sensor coordinates are not necessarily normalized from 0.0 to 1.0. Some implementations may have a different opaque coordinate system.
Example
const cameraPoint = { x: 0.5, y: 0.5 }
const depthPoint = depth.convertCameraPointToDepthPoint(cameraPoint)
console.log(depthPoint) // { x: 960, y: 360 }convertDepthPointToCameraPoint()
Converts the given depthPoint in
Depth coordinates relative to this Depth
into a Point in camera sensor coordinates.
Note
Camera sensor coordinates are not necessarily normalized from 0.0 to 1.0. Some implementations may have a different opaque coordinate system.
Example
const depthPoint = { x: depth.width / 2, y: depth.height / 2 }
const cameraPoint = depth.convertDepthPointToCameraPoint(depthPoint)
console.log(cameraPoint) // { x: 0.5, y: 0.5 }getDepthData()
getDepthData(): ArrayBufferGets the Depth's depth data as a full contiguous ArrayBuffer.
Discussion
This does not perform a copy, but since the Depth's data is stored
on the GPU, it might lazily perform a GPU -> CPU download.
Discussion
Once the Depth frame gets invalidated (isValid == false),
this ArrayBuffer is no longer safe to access.
Throws
If this Depth is invalid (isValid).
getNativeBuffer()
getNativeBuffer(): NativeBufferGet a NativeBuffer that points to
this Depth frame.
This is a shared contract between libraries to pass native buffers around without natively typed bindings.
The NativeBuffer must be released
again by its consumer via release(),
otherwise the Camera pipeline might stall.
rotate()
rotate(orientation: Orientation, isMirrored: boolean): DepthReturns a derivative Depth frame by rotating
it to the specified orientation, and potentially
mirroring it.
rotateAsync()
rotateAsync(orientation: Orientation, isMirrored: boolean): Promise<Depth>Asynchronously returns a derivative Depth frame by rotating
it to the specified orientation, and potentially
mirroring it.
toFrame()
toFrame(): FrameConverts this Depth frame to a Frame.
The resulting Frame will contain the depth/disparity
data in the current depth/disparity Format.
You must release the resulting Frame again manually
using Frame.dispose().
toFrameAsync()
Asynchronously converts this Depth frame to a Frame.
The resulting Frame will contain the depth/disparity
data in the current depth/disparity Format.
You must release the resulting Frame again manually
using Frame.dispose().