Depth

interface Depth extends HybridObject

A 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: number

Get 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: CameraCalibrationData

Gets 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: DepthDataAccuracy

Gets 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.

Note

If this Depth is invalid (isValid), this just returns 'unknown'.


depthDataQuality

readonly depthDataQuality: DepthDataQuality

Gets the quality classification of this Depth.

  • 'high': High quality depth data.
  • 'low': Lower quality depth data.
  • 'unknown': Quality is unknown or unavailable.

Note

If this Depth is invalid (isValid), this just returns 'unknown'.


height

readonly height: number

Gets the total height of this Depth.

Note

If this Depth is invalid (isValid), this may return 0.


isDepthDataFiltered

readonly isDepthDataFiltered: boolean

Gets 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: boolean

Gets whether this Depth frame is mirrored alongside the vertical axis.


isValid

readonly isValid: boolean

Gets 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: Orientation

The 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: DepthPixelFormat

Gets 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.

Note

If this Depth frame is invalid (isValid), this just returns 'unknown'.


timestamp

readonly timestamp: number

Gets the presentation timestamp this Depth was timed at.

Note

If this Depth is invalid (isValid), this may return 0.


width

readonly width: number

Gets the total width of this Depth.

Note

If this Depth is invalid (isValid), this may return 0.

Methods

convert()

convert(pixelFormat: DepthPixelFormat): Depth

Converts 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()

convertCameraPointToDepthPoint(cameraPoint: Point): Point

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()

convertDepthPointToCameraPoint(depthPoint: Point): Point

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(): ArrayBuffer

Gets 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(): NativeBuffer

Get 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): Depth

Returns 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(): Frame

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().


toFrameAsync()

toFrameAsync(): Promise<Frame>

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().