Skip to main content
Version: 06 Nov 2023


NameSpace: MagicLeap

APIs to access the depth camera data. More...

Inherits from:
MLAutoAPISingleton< MLDepthCamera >,
MLLazySingleton< T >

Detailed Description

public class MLDepthCamera : MLAutoAPISingleton< MLDepthCamera > 


This is an experimental API which may be modified or removed without any prior notice.

The API only supports reading data from the depth camera. Apps cannot modify the camera settings, support for the same may be added in a future release.

Public Fields


The settings the Depth Camera is currently configured with.

public static Settings CurrentSettings { get; set; }

SettingsDepth Camera Settings


public static bool IsConnected { get; set; }

Public Methods

MLResult Connect

Connect to depth camera.

public static MLResult Connect()


API Level 29

permissions com.magicleap.permission.DEPTH_CAMERA (protection level: dangerous)

Returns: MLResult.Code.InvalidParam: One of the parameters is invalid. MLResult.Code.Ok: Connected to camera device(s) successfully. MLResult.Code.PermissionDenied: Necessary permission is missing. MLResult.Code.LicenseError: Necessary license is missing. MLResult.Code.UnspecifiedFailure: The operation failed with an unspecified error.

MLResult Disconnect

Disconnect from depth camera.

public static MLResult Disconnect()


API Level 29

permissions None

Returns: MLResult.Code.InvalidParam: The camera's handle was invalid. MLResult.Code.Ok: Disconnected camera successfully. MLResult.Code.UnspecifiedFailure: Failed to disconnect camera for some unknown reason.

MLResult GetCapabilities

public static MLResult GetCapabilities(
out StreamCapability [] capabilities


out StreamCapability []capabilitiesStructure to encapsulate a possible configuration for a single stream. Can be used to understand possible values for a specific StreamConfig element in MLDepthCameraSettings. The capabilities supported by the depth camera can be queried with InternalGetCapabilities().

MLResult GetLatestDepthData

Poll for Frames.

public static MLResult GetLatestDepthData(
ulong timeoutMs,
out Data data


ulongtimeoutMsTimeout in milliseconds.
out DatadataDepth camera data. Will be null if no valid data is available when called.


Returns a Data object referencing the latest available frame data, if any.

This is a blocking call. API is not thread safe.

If there are no new depth data frames for a given duration (duration determined by the system) then the API will return MLResult.Code.Timeout.

API Level 29

permissions None

Returns: MLResult.Code.InvalidParam: The camera's handle was invalid. MLResult.Code.Ok: Depth camera data fetched successfully. MLResult.Code.Timeout: No frame available within time limit. MLResult.Code.UnspecifiedFailure: Failed due to internal error.

void SetSettings

Sets the current settings of Depth Camera.

public static void SetSettings(
Settings settings



MLResult UpdateSettings

Update the depth camera settings.

public static MLResult UpdateSettings(
Settings settings


SettingssettingsNew Settings for the depth camera.


API Level 29

permissions None

Returns: MLResult.Code.InvalidParam: The camera's handle was invalid. MLResult.Code.Ok: Settings updated successfully. MLResult.Code.UnspecifiedFailure: Failed due to internal error.

Protected Methods


Callback sent to all MagicLeap APIs on application pause.

protected virtual override void OnApplicationPause(
bool pauseStatus


boolpauseStatusTrue if the application is paused, else False.

Reimplements: OnApplicationPause


Do API-specific creation/initialization of ML resources for this API, such as creating trackers, etc. Called automatically the first time Instance is accessed. Error checking on the return value is performed in the base class.

protected virtual override MLResult.Code StartAPI()

Reimplements: StartAPI


API-specific cleanup. Will be called whenever MLDevice is destroyed (at the latest, when the application is shutting down). Error checking on the return value is performed in the base class.

protected virtual override MLResult.Code StopAPI()

Reimplements: StopAPI

Public Attributes


public const int FrameTypeCount = 2;

Public Enums


Flags used to specify what kind of data to request from Depth Camera

DepthImage1 << 0Enable DepthImage. See Data.DepthImage for more details.
Confidence1 << 1Enable ConfidenceBuffer. See Data.ConfidenceBuffer for more details.
DepthFlags1 << 2Enable DepthFlagsBuffer. See Data.DepthFlagsBuffer for more details.
AmbientRawDepthImage1 << 3Enable AmbientRawDepthImage. See Data.AmbientRawDepthImage for more details.
RawDepthImage1 << 4Enable RawDepthImage. See Data.RawDepthImage for more details.


Flags to select data requested from depth camera.

Valid0 << 0Indicates that there is no additional flag data for this pixel.
Invalid1 << 0This bit is set to one to indicate that one or more flags from below have been set. Depending on the use case the application can correlate the flag data and corresponding pixel data to determine how to handle the pixel
Saturated1 << 1The pixel intensity is either below the min or the max threshold value.
Inconsistent1 << 2Inconsistent data received when capturing frames. This can happen due to fast motion.
LowSignal1 << 3Pixel has very low signal to noise ratio. One example of when this can happen is for pixels in far end of the range.
FlyingPixel1 << 4This typically happens when there is step jump in the distance of adjoining pixels in the scene. Example: When you open a door looking into the room the edges along the door's edges can cause flying pixels.
Masked1 << 5If this bit is on it indicates that the corresponding pixel may not be within the projector's illumination cone.
SBI1 << 8This bit will be set when there is high noise.
StrayLight1 << 9This could happen when there is another light source apart from the depth camera projector. This could also lead to LowSignal.
ConnectedComponent1 << 10If a small group of Valid is sorrunded by a set of Invalid then this bit will be set to 1.


Enumeration of possible frame rates



Depth Camera frame capture types

LongRangeFrame captured using Stream.LongRange mode.
ShortRangeFrame captured using Stream.ShortRange mode.


Depth Camera modes Future release may add support to other modes.

LongRange1 << 0Long range mode Under normal operations long range mode has a maximum frequency of 5fps and a range of up to 5m, in some cases this can go as far 7.5m.
ShortRange1 << 1Short range mode Under normal operations short range stream has a maximum frequency of 60fps and a range from 0.2m up to 0.9m.