Table Of Contents

Previous topic

CameraDevice Prefab

Next topic

CloudRecognizer Prefab

CameraDeviceBaseBehaviour Class

Inherits: DeviceAbstractBehaviour

Description

CameraDeviceBaseBehaviour is the component to control CameraDevice in the AR scene.

A CameraDevice works on its own thread. You can Open/Close a camera. You can also close and reopen a different camera with different input parameters at any point. StartCapture/StopCapture is used to stat or stop the camera preview but keep pre-set camera parameters. The control methods are similar to those provided in the system API.

CameraDevice is the input source of trackers and other algorithms. CameraDeviceBaseBehaviour contains the entrance of AR chain, OpenAndStart.

Below code shows how to dynamically switch to Front camera when the Back camera is being used and the track is running.

ARBuilder.Instance.CameraDeviceBehaviours[0].Close();
ARBuilder.Instance.CameraDeviceBehaviours[0].CameraDeviceType = CameraDeviceBaseBehaviour.DeviceType.Front;
ARBuilder.Instance.CameraDeviceBehaviours[0].OpenAndStart();

Front Camera & Horizontal Flip

When you are using front camera on Android and iOS and HorizontalFlip is set to false or HorizontalFlip set to true in other conditions, EasyAR will turn on the horizontal flip mode.

When horizontal flip mode is on, the camera image will be horizontally flipped from the raw data when display, and

  1. GL.SetRevertBackfacing(true) will be called in RenderCameraBaseBehaviour.OnPreRender
  2. GL.SetRevertBackfacing(false) will be called in RenderCameraBaseBehaviour.OnPostRender (since 2.1.0)

But the camera data used for tracking will never be flipped.

The default behavior is made to be same with system camera. It makes you feel like looking into a mirror when you are using front camera. You can always change the default behavior by reversing HorizontalFlip.

Public Types

enum FocusMode{Normal, Triggerauto, Continousauto, Infinity, Macro}
enum DeviceType{Default, Back, Front}

Public Properties

DeviceType CameraDeviceType
int CameraIndex
bool HorizontalFlip
CameraCalibration Calibration
float FPS
Vector2I DeviceSize
float[] SupportedFPS
Vector2I[] SupportedSize
float ZoomScale
float MinZoomScale
float MaxZoomScale

Public Fields

float CameraFPS
Vector2 CameraSize
bool CaptureWhenStart
bool RequestPlatformPermission

Public Functions

void Close()
void OpenAndStart()
bool StartCapture()
bool StopCapture()
bool SetFlashTorchMode(bool on)
bool SetFocusMode(FocusMode focusMode)

Overwritten MonoBahaviour Functions

protected virtual void OnDestroy()
protected virtual void Start()

enum FocusMode

Constant Value Description
Normal 0 Normal auto focus mode. You should call SetFocusMode(FocusMode.Triggerauto) to start the focus in this mode.
Triggerauto 1 Triggers auto focus. Focus mode will be set to FocusMode.Normal.
Continousauto 2 Continuous auto focus mode.
Infinity 3 Infinity focus mode.
Macro 4 Macro (close-up) focus mode. You should call SetFocusMode(FocusMode.Triggerauto) to start the focus in this mode.

enum Device

Constant Value Description
Default 0 The default camera device.
Back 1 The back faced camera device.
Front 2 The front faced camera device.

DeviceType CameraDeviceType

Device type to open. On desktop OSes, Device.Default represents the default camera and the value > 0 represents the device number (start from 1). It must be set before OpenAndStart.

If CameraIndex is set to none-zero, the open method will use CameraIndex and ignore CameraDeviceType, otherwise the open method will use CameraDeviceType to open the camera of specific type.

int CameraIndex

Device index to open. On desktop OSes, 0 represents the default camera and the value > 0 represents the device number (start from 1). It must be set before OpenAndStart.

If CameraIndex is set to none-zero, the open method will use CameraIndex and ignore CameraDeviceType, otherwise the open method will use CameraDeviceType to open the camera of specific type.

bool HorizontalFlip

The horizontal flip flag. When set, the camera image will be horizontal flipped from default when display.

When you are using front camera on Android and iOS and HorizontalFlip is set to false or HorizontalFlip set to true in other conditions, EasyAR will turn on the horizontal flip mode.

When horizontal flip mode is on, the camera image will be horizontally flipped from the raw data when display, and

  1. GL.SetRevertBackfacing(true) will be called in RenderCameraBaseBehaviour.OnPreRender
  2. GL.SetRevertBackfacing(false) will be called in RenderCameraBaseBehaviour.OnPostRender (since 2.1.0)

But the camera data used for tracking will never be flipped.

The default behavior is made to be same with system camera. It makes you feel like looking into a mirror when you are using front camera. You can always change the default behavior by reversing HorizontalFlip.

float FPS

Current frame rate. The proximal value available will be selected for set. Use after a successful Open.

float[] SupportedFPS

The supported frame rate. Use after a successful Open.

Vector2I DeviceSize

Current preview size. The proximal value available will be selected for set. Use after a successful Open.

Vector2I[] SupportedSize

The supported preview size. Use after a successful Open.

CameraCalibration Calibration

Calibration data. Use after a successful Open.

float ZoomScale

Camera zoom scale. Use after a successful Open.

float MinZoomScale

Minimal camera zoom scale. Use after a successful Open.

float MaxZoomScale

Maximal camera zoom scale. Use after a successful Open.

float CameraFPS

Camera fps. The set must be called before OpenAndStart.

Vector2 CameraSize

Camera size. The set must be called before OpenAndStart.

bool CaptureWhenStart

Whether to open device and start capture at the MonoBehaviour.Start. If false, you must call OpenAndStart to bootup the AR chain.

bool RequestPlatformPermission

Request platform permission for camera when open. If false, you have to make sure to request the permission by yourself.

void Close()

Closes the camera and the whole connected AR chain will stop. You can change bindings using bind calls and camera devices using CameraDeviceType. Call OpenAndStart to restart.

void OpenAndStart()

Open the device of type CameraDeviceType and start capture immediately.

This is start point of the AR scene. All connections (all bind calls) except ImageTargetBaseBehaviour.Bind must be done before calling this function. It will use the connections established in the bind calls to bootup the whole AR scene.

bool StartCapture()

Starts the capture.

bool StopCapture()

Stops the capture. All connections and configurations are kept unchanged.