VideoKit
Search…
⌃K

VideoKitCameraManager

class NatML.VideoKit.VideoKitCameraManager : MonoBehaviour
This components manages camera streaming in a scene. This component can be added to any game object in the scene.

Configuring the Manager

The manager uses top-level properties to control which camera is used, the preview resolution, and whether to start streaming the preview immediately the scene is opened:

Specifying the Preview Resolution

/// <summary>
/// Desired camera resolution.
/// </summary>
Resolution resolution { get; set; }
The resolution determines the preview resolution of the camera stream. The following resolution presets are supported:
/// <summary>
/// Camera resolution presets.
/// </summary>
enum Resolution {
/// <summary>
/// Use the default camera resolution.
/// With this preset, the camera resolution will not be set.
/// </summary>
Default = 0,
/// <summary>
/// Lowest resolution supported by the camera device.
/// </summary>
Lowest = 1,
/// <summary>
/// SD resolution.
/// </summary>
_640x480 = 2,
/// <summary>
/// HD resolution.
/// </summary>
_1280x720 = 3,
/// <summary>
/// Full HD resolution.
/// </summary>
_1920x1080 = 4,
/// <summary>
/// Highest resolution supported by the camera device.
/// Using this resolution is strongly not recommended.
/// </summary>
Highest = 5
}
The resolution is always specified in landscape format, meaning that the width is always greater than the height.

Specifying the Camera Capabilities

/// <summary>
/// Desired camera capabilities.
/// </summary>
Capabilities capabilities { get; set; }
The capabilities are used to configure the camera session to provide certain types of data while streaming. The following capabilities are supported:
/// <summary>
/// Camera manager capabilities.
/// </summary>
[Flags]
enum Capabilities {
/// <summary>
/// Stream depth data along with the camera preview data.
/// This flag adds a minimal performance cost, so enable it only when necessary.
/// </summary>
Depth = 1,
/// <summary>
/// Ensure that the camera preview data can be used for machine learning predictions.
/// Enabling this adds a minimal performance impact so it should be disabled when not needed.
/// </summary>
MachineLearning = 2,
/// <summary>
/// Generate a human segmentation texture while streaming the camera preview.
/// This flag adds a variable performance cost, so enable it only when necessary.
/// </summary>
HumanTexture = 6,
/// <summary>
/// Detect human pose data while streaming the camera preview.
/// This flag adds a variable performance cost, so enable it only when necessary.
/// </summary>
PoseDetection = 10,
}
On WebGL, the MachineLearning capability is always enabled.

Starting the Camera on Awake

/// <summary>
/// Whether to start the camera preview as soon as the component awakes.
/// </summary>
bool playOnAwake { get; set; }
The playOnAwake property determines whether to start the camera preview as soon as the component awakes.

Configuring the Camera

The manager provides some camera control properties:

Specifying the Streaming Camera

/// <summary>
/// Get ot set the camera device used to stream camera images.
/// </summary>
CameraDevice cameraDevice { get; set; }
The cameraDevice used for streaming can be set. If the device is set while the preview is running, the manager will switch the camera to stream from the device that is set.
See Using Cameras for more information on working with camera devices.

Specifying the Focus Mode

/// <summary>
/// Desired camera focus mode.
/// </summary>
CameraDevice.FocusMode focusMode { get; set; }
The focusMode property can be used to set the camera focus mode when starting the preview.
See CameraDevice.FocusMode for the supported focus modes.

Specifying the Exposure Mode

/// <summary>
/// Desired camera exposure mode.
/// </summary>
CameraDevice.ExposureMode exposureMode { get; set; }
The exposureMode property can be used to set the camera exposure mode when starting the preview.
See CameraDevice.ExposureMode for the supported exposure modes.

Checking the Preview State

/// <summary>
/// Whether the camera is running.
/// </summary>
bool running { get; }
The running property reports whether the camera preview is currently running.
Because starting the camera preview is asynchronous, the value of this property is not guaranteed to be the same as cameraDevice.running. Use this property instead.

Starting the Camera Preview

/// <summary>
/// Start the camera preview.
/// </summary>
void StartRunning ();
The camera preview is started with the StartRunning method.

Stopping the Camera Preview

/// <summary>
/// Stop the camera preview.
/// </summary>
void StopRunning ();
The camera preview is stopped with the StopRunning method.

Handling Camera Frames

/// <summary>
/// Event raised when the camera preview starts.
/// </summary>
UnityEvent<CameraFrame> OnFrame { get; set; }
The OnFrame method is invoked with camera frames as they are streamed from the camera. This event can be used to implement video filters.