Getting Started with EasyAR
Header:#include "easyar/camera.hpp"
Inherits:RefBase

Description

CameraDevice is the class represent a device camera.

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. start/stop is used to stat or stop the camera preview but keep pre-set camera parameters and algorithm connections. The control methods are similar to those provided in the system API.

CameraDevice is the input source of trackers and other algorithms. You should call open before any other methods, otherwise they will have no effect. All algorithms can only work after a CameraDevice is attached. If a CameraDevice is closed, all algorithms will lost attach to the CameraDevice and a reopen will not restore the connections.

Public Types

enumFocusMode{kFocusModeNormal, kFocusModeTriggerauto, kFocusModeContinousauto, kFocusModeInfinity, kFocusModeMacro}
enumDevice{kDeviceDefault, kDeviceBack, kDeviceFront}

Public Functions

CameraDevice()
virtual~CameraDevice()
boolopen(int camera = kDeviceDefault)
boolclose()
virtual boolstart()
virtual boolstop()
boolisOpened()
floatframeRate() const
intsupportedFrameRateCount() const
floatsupportedFrameRate(int idx) const
boolsetFrameRate(float fps)
Vec2Isize() const
intsupportedSizeCount() const
Vec2IsupportedSize(int idx) const
boolsetSize(Vec2I size)
CameraCalibrationcameraCalibration() const
boolsetFlashTorchMode(bool on)
boolsetFocusMode(FocusMode focusMode)
voidsetHorizontalFlip(bool flip) (since 1.3.0)

enum CameraDevice::FocusMode

ConstantValueDescription
kFocusModeNormal0Normal auto focus mode. You should call setFocusMode(kFocusModeTriggerauto) to start the focus in this mode.
kFocusModeTriggerauto1Triggers auto focus. Focus mode will be set to kFocusModeNormal.
kFocusModeContinousauto2Continuous auto focus mode.
kFocusModeInfinity3Infinity focus mode.
kFocusModeMacro4Macro (close-up) focus mode. You should call setFocusMode(kFocusModeTriggerauto) to start the focus in this mode.

enum CameraDevice::Device

ConstantValueDescription
kDeviceDefault0The default camera device.
kDeviceBack1The back faced camera device.
kDeviceFront2The front faced camera device.

CameraDevice()

Creates a CameraDevice object.

virtual ~CameraDevice()

Destroys the CameraDevice object.

bool open(int camera = kDeviceDefault)

Opens a camera with camera device type. On desktop OSes, kDeviceDefault represents the default camera and the value > 0 represents the device number (start from 1).

bool close()

Closes a camera. If a CameraDevice is closed, all algorithms will lose attach to the CameraDevice and a reopen will not restore the connections.

virtual bool start()

Starts the capture.

virtual bool stop()

Stops the capture. Only stops the capture process, all parameters and connections with algorithms are kept unchanged.

bool isOpened()

Returns true if the CameraDevice is opened, false otherwise. It is useful for the functions getting parameters because only an opened camera will return valid values.

float frameRate() const

Gets the current frame rate. Use after a successful open.

int supportedFrameRateCount() const

Gets the number of supported frame rate. Use after a successful open.

float supportedFrameRate(int idx) const

Gets the supported frame rate of index idx. Returns 0 if idx is out of range. Use after a successful open.

bool setFrameRate(float fps)

Sets the frame rate. The proximal value available will be selected, use frameRate to get the frame rate. Use after a successful open.

Vec2I size() const

Gets the current preview size. Use after a successful open.

int supportedSizeCount() const

Gets the number of supported preview size. Use after a successful open.

Vec2I supportedSize(int idx) const

Gets the supported preview size of index idx. Returns {0, 0} if idx is out of range. Use after a successful open.

bool setSize(Vec2I size)

Sets the preview size. The proximal value available will be selected, use size to get the actual size. Use after a successful open.

CameraCalibration cameraCalibration() const

Gets calibration data. Use after a successful open.

bool setFlashTorchMode(bool on)

Sets flash torch mode to on. Use after a successful open.

bool setFocusMode(FocusMode focusMode)

Sets focus mode to focusMode. Use after start.

void setHorizontalFlip(bool flip) (since 1.3.0)

Set horizontal flip flag to the camera. When set, the camera image will be horizontal flipped from default. Use after a successful open.