owlcamera_web_logo

OwlCamera C++ library

v3.1.0

Table of contents

Overview

The OwlCamera C++ library is a software controller for Raptor Owl 640 and OWL 1280 cameras. The OwlCamera library inherits the Camera interface. It depends on the following libraries: Camera interface library (provides interface and data structures to control cameras), Logger logging library (provides functions to print log information in console and files), OwlParser (provides functions for encoding commands; it is a part of this repository: folder src/parser, see src/parser/README.md) and SerialPort (provides functions to work with serial ports). The Camera library depends on the ConfigReader library. The OwlCamera library provides a simple interface to be integrated in any C++ projects. The repository of the library does not contain the other libraries it depends on: they are cloned next to the repository (see Build stand alone) or are added by the project that includes OwlCamera (see Connect to your project). The libraries do not need to be specially installed in the OS. It is developed with C++17 standard and compatible with Linux and Windows.

OwlCamera is general-purpose software: it is not tied to any sector or application, and the developer of a program decides what the program does with it.

The library code was developed by reverse engineering the serial port communication protocol of the cameras.

Versions

Table 1 - Library versions.

Version Release date What’s new
1.0.0 30.05.2023 - First version.
2.0.0 07.03.2024 - Interface updated.
- Test application updated.
- Documentation updated.
2.0.1 29.03.2024 - Code review and documentation update.
2.0.2 23.05.2024 - Documentation updated.
- Submodules updated.
2.0.3 07.08.2024 - CMake updated.
2.0.4 16.09.2024 - Fix connection status.
2.0.5 05.10.2024 - Add NUC command.
2.0.6 22.11.2024 - Add NUC mode control.
2.0.7 03.04.2025 - Logger submodule update.
2.0.8 19.07.2025 - Fix NUC mode options control.
2.0.9 26.10.2025 - OwlParser submodule update.
- SerialPort submodule update.
3.0.0 21.03.2026 - Updated OwlParser submodules.
- Added new commands support.
3.0.1 12.10.2026 - Submodules updated.
3.0.2 17.10.2026 - Sub-repositories removed: the libraries OwlCamera depends on are expected in the folders next to the repository (see Build stand alone).
- Values of params are checked before use: a value that is not a finite number, doesn’t fit the integer type of the param or is outside of the allowed range is rejected without any command to the camera (before, the conversion of such a value was undefined).
- Data of a command (decodeAndExecuteCommand(…)) is checked: a null pointer, a size different from 7 bytes (COMMAND) or 11 bytes (SET_PARAM) and an unknown ID are rejected (before, a damaged SET_PARAM message could execute a command).
- Data received from the camera can’t change the command that is sent to the camera.
- A command that the serial port accepted only partly is written to the end; commands of one call are not mixed with commands of other threads.
- LOG_MODE is applied to all log messages.
- Compiler warning and hardening options added to CMake files.
- Test application reworked: it controls camera params from the terminal only.
3.1.0 29.10.2026 - The OwlParser library is a part of the repository (folder src/parser) and is not a separate dependency any more.

Library files

The library supplied by source code only. The user would be given a set of files in the form of a CMake project (repository). The libraries OwlCamera depends on, except the protocol parser OwlParser (folder src/parser), are separate repositories and are not included. The repository structure is shown below:

CMakeLists.txt ---------------------- Main CMake file of the library.
static ------------------------------ Folder with images of this document.
src --------------------------------- Folder with source code of the library.
    CMakeLists.txt ------------------ CMake file of the library.
    OwlCamera.cpp ------------------- C++ implementation file.
    OwlCamera.h --------------------- Header file which includes OwlCamera class declaration.
    OwlCameraVersion.h -------------- Header file which includes version of the library.
    OwlCameraVersion.h.in ----------- CMake service file to generate version file.
    parser -------------------------- Protocol parser library (former OwlParser repository).
        .gitignore ------------------ Git ignore rules of the parser folder.
        CMakeLists.txt -------------- Main CMake file of the parser library.
        README.md ------------------- Documentation of the parser library.
        src ------------------------- Folder with source code of the parser library.
            CMakeLists.txt ---------- CMake file of the parser library.
            OwlParser.cpp ----------- C++ implementation file of the parser library.
            OwlParser.h ------------- Header file which includes OwlParser class declaration.
            OwlParserVersion.h ------ Header file which includes version of the parser library.
            OwlParserVersion.h.in --- CMake service file to generate version file.
        static ---------------------- Folder with images of the parser documentation.
            owlparser_web_logo.png -- Logo of the parser library.
        test ------------------------ Folder with test application of the parser (not built by the library).
            CMakeLists.txt ---------- CMake file for test application of the parser.
            main.cpp ---------------- Source code file of test application of the parser.
test -------------------------------- Folder with source code of the test application.
    CMakeLists.txt ------------------ CMake file of test application.
    main.cpp ------------------------ Test application source code.

OwlCamera class description

OwlCamera Class declaration

The OwlCamera interface class declared in OwlCamera.h file. The OwlCamera class inherits Camera interfaces. All public methods of the class are thread-safe. Class declaration:

namespace rapidpixel
{
class OwlCamera : public rapidpixel::Camera
{
public:

  /// Default constructor.
  OwlCamera() = default;

  /// Class destructor. Closes the serial port.
  ~OwlCamera() override = default;

  /// Copy and move constructors and assignment operators are deleted.
  OwlCamera(const OwlCamera&) = delete;
  OwlCamera(OwlCamera&&) = delete;
  OwlCamera& operator= (const OwlCamera&) = delete;
  OwlCamera& operator= (OwlCamera&&) = delete;

  /// Get Camera class version.
  static std::string getVersion();

  /// Open camera controller (open the serial port).
  bool openCamera(std::string initString) override;

  /// Init camera controller by parameters class.
  bool initCamera(CameraParams& params) override;

  /// Close camera serial port.
  void closeCamera() override;

  /// Get camera open status.
  bool isCameraOpen() override;

  /// Get camera connection status.
  bool isCameraConnected() override;

  /// Set the camera controller param.
  bool setParam(CameraParam id, float value) override;

  /// Get the camera controller param.
  float getParam(CameraParam id) override;

  /// Get the camera controller params.
  void getParams(CameraParams& params) override;

  /// Execute camera controller action command.
  bool executeCommand(CameraCommand id) override;

  /// Decode and execute command.
  bool decodeAndExecuteCommand(uint8_t* data, int size) override;
};
}

getVersion method

The getVersion() returns string of OwlCamera class version. Method declaration:

static std::string getVersion();

Method can be used without OwlCamera class instance:

std::cout << "OwlCamera class version: " <<
             rapidpixel::OwlCamera::getVersion() << std::endl;

Console output:

OwlCamera class version: 3.1.0

openCamera method

The openCamera(…) opens serial port to communicate with camera (baudrate 115200, 8 data bits, no parity, 1 stop bit). The serial port name is passed to the operating system as is. The method does nothing if the serial port is already open. Method declaration:

bool openCamera(std::string initString) override;
Parameter Value
initString Initialization string. The first non-empty segment before ‘;’ is the serial port name (for example “/dev/ttyUSB0” on Linux). The whole string is used if there is no ‘;’ or all segments are empty. The baudrate is always 115200.

Returns: TRUE if the camera controller is opened (also if it is already open) or FALSE if the serial port name is empty or the serial port can’t be opened.

initCamera method

The initCamera(…) initializes controller and sets camera params (Camera interface). The method sets the params TYPE and LOG_MODE, calls openCamera(…) method with the initString field and after that sets the other camera params of the structure with setParam(…) method in the following order: NUC_MODE, EXPOSURE_MODE, EXPOSURE_TIME, GAIN_MODE, GAIN, IMAGE_FLIP, FPS (only if it is greater than 0), AGC_MODE, BRIGHTNESS, ROI_X0, ROI_Y0, ROI_X1, ROI_Y1, CUSTOM_1, CUSTOM_2 and CUSTOM_3. Method declaration:

bool initCamera(CameraParams& params) override;
Parameter Value
params CameraParams class object.

Returns: TRUE if the serial port is opened or FALSE if not. The result of setting of the individual params is not returned: a param that is rejected (for example AGC_MODE for OWL 1280 camera) is skipped. Use getParam(…) or getParams(…) method to check the actual values.

closeCamera method

The closeCamera() method closes serial port. Method declaration:

void closeCamera() override;

isCameraOpen method

The isCameraOpen() method returns controller initialization status. Open status shows if the controller initialized (serial port open) but doesn’t show if controller has communication with equipment. For example, if serial port is open (opens serial port file in OS) but equipment can be not active (no power). In this case open status just shows that the serial port is open. Method declaration:

bool isCameraOpen() override;

Returns: TRUE if the controller initialized (serial port open) or FALSE if not.

isCameraConnected method

The isCameraConnected() shows the status of the data exchange with the equipment (camera). The library sends commands only and does not read responses of the camera, so the status is TRUE after the serial port is opened and after every command that was written to the serial port, and FALSE if the serial port is closed or the last command was not written to the serial port. The status doesn’t show if the camera is powered. Method declaration:

bool isCameraConnected() override;

Returns: TRUE if the last command was written to the serial port (or no command was sent after the serial port was opened) or FALSE if not.

setParam method

The setParam(…) method sets the camera controller parameter value. The value of a param is a float, an integer param gets the value with the fractional part dropped (truncated towards zero). A value that is NaN, infinite, doesn’t fit the integer type of the param or is outside of the range given in Table 3 is rejected: the method returns FALSE, nothing is sent to the camera and the param is not changed. Values of the params that are bit fields of a camera register (EXPOSURE_TIME, GAIN, ROI_X0, ROI_Y0, ROI_X1, ROI_Y1, CUSTOM_1, CUSTOM_2, CUSTOM_3) are not checked against the range of the register: the camera gets the least significant bits of the value that fit the register (see Table 3). The method sends one or several commands to the camera. The commands of one call are not mixed with the commands of other calls. If the camera type is not set (param TYPE) the commands of OWL 640 camera are sent. Method declaration:

bool setParam(CameraParam id, float value) override;
Parameter Description
id Camera controller parameter ID according to CameraParam enum.
value Parameter value. Value depends on parameter ID.

Returns: TRUE if the parameter was set (the commands were written to the serial port) or FALSE if not: the param is not supported, the value is rejected or the commands were not written to the serial port. The params TYPE and LOG_MODE are not sent to the camera.

getParam method

The getParam(…) method is intended to obtain a Camera parameter value. Method declaration:

float getParam(CameraParam id) override;
Parameter Description
id Camera controller parameter ID according to CameraParam enum.

Returns: parameter value or -1 if the parameter is not supported.

getParams method

The getParams(…) method is intended to obtain Camera parameters structure. Method declaration:

void getParams(CameraParams& params) override;
Parameter Description
params Reference to CameraParams class instance.

executeCommand method

The executeCommand(…) method is intended to execute a Camera action command. Supported commands are listed in Table 2. Method declaration:

bool executeCommand(CameraCommand id) override;
Parameter Description
id Camera controller command ID according to CameraCommand enum.

Returns: TRUE if the command was executed (written to the serial port) or FALSE if not: the command is not supported or was not written to the serial port.

decodeAndExecuteCommand method

The decodeAndExecuteCommand(…) method decodes and executes a command on the controller side. The method will decode commands encoded by encodeCommand(…) and encodeSetParamCommand(…) methods of the Camera interface class. If the command is decoded, the method will call the setParam(…) or executeCommand(…) methods for the camera interface. A message is rejected and nothing is sent to the camera if the pointer is null, the size is not 7 bytes (COMMAND) or 11 bytes (SET_PARAM), the version or the type of the message is wrong or the ID is not supported. This method is thread-safe. This means that the method can be safely called from any thread. Method declaration:

bool decodeAndExecuteCommand(uint8_t* data, int size) override;
Parameter Description
data Pointer to input command data. Must not be nullptr. The pointer must be valid for size bytes.
size Size of command. Must be 11 bytes for SET_PARAM and 7 bytes for COMMAND.

Returns: TRUE if command decoded (SET_PARAM or COMMAND) and executed (action command or set param command) or FALSE if not.

encodeSetParamCommand method of Camera class

The encodeSetParamCommand(…) static method encodes command to change any remote camera parameter. To control a camera remotely, the developer has to design his own protocol and according to it encode the command and deliver it over the communication channel. To simplify this, the Camera class contains static methods for encoding the control command. The Camera class provides two types of commands: a parameter change command (SET_PARAM) and an action command (COMMAND). encodeSetParamCommand(…) designed to encode SET_PARAM command. Method declaration:

static void encodeSetParamCommand(uint8_t* data, int& size, CameraParam id, float value);
Parameter Description
data Pointer to data buffer for encoded command. Must have size >= 11.
size Size of encoded data. Will be 11 bytes.
id Parameter ID according to CameraParam enum.
value Parameter value.

encodeSetParamCommand(…) is static and used without Camera class instance. This method used on client side (control system). Command encoding example:

// Buffer for encoded data.
uint8_t data[11];
// Size of encoded data.
int size = 0;
// Parameter value.
const float outValue = 10.0f;
// Encode command.
rapidpixel::Camera::encodeSetParamCommand(
    data, size, rapidpixel::CameraParam::ROI_X0, outValue);

encodeCommand method of Camera class

The encodeCommand(…) static method encodes action command for camera remote control. To control a camera remotely, the developer has to design his own protocol and according to it encode the command and deliver it over the communication channel. To simplify this, the Camera class contains static methods for encoding the control command. The Camera class provides two types of commands: a parameter change command (SET_PARAM) and an action command (COMMAND). encodeCommand(…) designed to encode COMMAND command (action command). Method declaration:

static void encodeCommand(uint8_t* data, int& size, CameraCommand id);
Parameter Description
data Pointer to data buffer for encoded command. Must have size >= 7.
size Size of encoded data. Will be 7 bytes.
id Command ID according to CameraCommand enum.

encodeCommand(…) is static and used without Camera class instance. This method used on client side (control system). Command encoding example:

// Buffer for encoded data.
uint8_t data[7];
// Size of encoded data.
int size = 0;
// Encode command.
rapidpixel::Camera::encodeCommand(data, size, rapidpixel::CameraCommand::NUC);

decodeCommand method of Camera class

The decodeCommand(…) static method decodes command on camera controller side encoded by encodeSetParamCommand(…) or encodeCommand(…). Method declaration:

static int decodeCommand(uint8_t* data, int size, CameraParam& paramId, CameraCommand& commandId, float& value);
Parameter Description
data Pointer to input command.
size Size of command. Must be 11 bytes for SET_PARAM and 7 bytes for COMMAND.
paramId Camera parameter ID according to CameraParam enum. After decoding SET_PARAM command the method will return parameter ID.
commandId Camera command ID according to CameraCommand enum. After decoding COMMAND the method will return command ID.
value Camera parameter value (after decoding SET_PARAM command).

Returns: 0 - in case decoding COMMAND, 1 - in case decoding SET_PARAM command or -1 in case errors.

Data structures

CameraCommand enum

Enum declaration:

namespace rapidpixel
{
enum class CameraCommand
{
    /// Restart camera controller.
    RESTART = 1,
    /// Do NUC.
    NUC,
    /// Apply settings.
    APPLY_PARAMS,
    /// Save params.
    SAVE_PARAMS,
    /// Menu on.
    MENU_ON,
    /// Menu off.
    MENU_OFF,
    /// Menu set.
    MENU_SET,
    /// Menu up.
    MENU_UP,
    /// Menu down.
    MENU_DOWN,
    /// Menu left.
    MENU_LEFT,
    /// Menu right.
    MENU_RIGHT,
    /// Freeze, Argument: time msec.
    FREEZE,
    /// Disable freeze.
    DEFREEZE
};
}

Table 2 - Camera commands description.

Command Description
RESTART Reset command.
NUC NUC (Flat Field Correction) command.
APPLY_PARAMS Not supported by OwlCamera library.
SAVE_PARAMS Not supported by OwlCamera library.
MENU_ON Not supported by OwlCamera library.
MENU_OFF Not supported by OwlCamera library.
MENU_SET Not supported by OwlCamera library.
MENU_UP Not supported by OwlCamera library.
MENU_DOWN Not supported by OwlCamera library.
MENU_LEFT Not supported by OwlCamera library.
MENU_RIGHT Not supported by OwlCamera library.
FREEZE Not supported by OwlCamera library.
DEFREEZE Not supported by OwlCamera library.

CameraParam enum

Enum declaration:

namespace rapidpixel
{
enum class CameraParam
{
    /// Video frame width. Value from 0 to 16384.
    WIDTH = 1,
    /// Video frame height Value from 0 to 16384.
    HEIGHT,
    /// Display menu mode.
    DISPLAY_MODE,
    /// Video output type.
    VIDEO_OUTPUT,
    /// Logging mode.
    LOG_MODE,
    /// Exposure mode.
    EXPOSURE_MODE,
    /// Exposure time of the camera sensor.
    EXPOSURE_TIME,
    /// White balance mode.
    WHITE_BALANCE_MODE,
    /// White balance area.
    WHITE_BALANCE_AREA,
    /// White dynamic range mode.
    WIDE_DYNAMIC_RANGE_MODE,
    /// Image stabilization mode.
    STABILIZATION_MODE,
    /// ISO sensitivity.
    ISO_SENSITIVITY,
    /// Scene mode.
    SCENE_MODE,
    /// FPS.
    FPS,
    /// Brightness mode.
    BRIGHTNESS_MODE,
    /// Brightness. Value 0 - 100%.
    BRIGHTNESS,
    /// Contrast. Value 1 - 100%.
    CONTRAST,
    /// Gain mode.
    GAIN_MODE,
    /// Gain. Value 1 - 100%.
    GAIN,
    /// Sharpening mode.
    SHARPENING_MODE,
    /// Sharpening. Value 1 - 100%.
    SHARPENING,
    /// Palette.
    PALETTE,
    /// Analog gain control mode.
    AGC_MODE,
    /// Shutter mode.
    SHUTTER_MODE,
    /// Shutter position. 0 (full close) - 65535 (full open).
    SHUTTER_POSITION,
    /// Shutter speed. Value: 0 - 100%.
    SHUTTER_SPEED,
    /// Digital zoom mode.
    DIGITAL_ZOOM_MODE,
    /// Digital zoom. Value 1.0 (x1) - 20.0 (x20).
    DIGITAL_ZOOM,
    /// Exposure compensation mode.
    EXPOSURE_COMPENSATION_MODE,
    /// Exposure compensation position. 
    EXPOSURE_COMPENSATION_POSITION,
    /// Defog mode.
    DEFOG_MODE,
    /// Dehaze mode.
    DEHAZE_MODE,
    /// Noise reduction mode.
    NOISE_REDUCTION_MODE,
    /// Black and white filter mode.
    BLACK_WHITE_FILTER_MODE,
    /// Filter mode.
    FILTER_MODE,
    /// NUC mode for thermal cameras.
    NUC_MODE,
    /// Auto NUC interval for thermal cameras. 
    AUTO_NUC_INTERVAL_MSEC,
    /// Image flip mode.
    IMAGE_FLIP,
    /// DDE mode.
    DDE_MODE,
    /// DDE level.
    DDE_LEVEL,
    /// ROI top-left horizontal position, pixels.
    ROI_X0,
    /// ROI top-left vertical position, pixels.
    ROI_Y0,
    /// ROI bottom-right horizontal position, pixels.
    ROI_X1,
    /// ROI bottom-right vertical position, pixels.
    ROI_Y1,
    /// Camera temperature, degree.
    TEMPERATURE,
    /// ALC gate.
    ALC_GATE,
    /// Sensor sensitivity.
    SENSITIVITY,
    /// Changing mode (day / night).
    CHANGING_MODE,
    /// Changing level (day / night).
    CHANGING_LEVEL,
    /// Chroma level. Values: 0 - 100%.
    CHROMA_LEVEL,
    /// Details, enhancement. Values: 0 - 100%.
    DETAIL,
    /// Camera settings profile.
    PROFILE,
    /// Connection status (read only). Shows if we have a response from camera.
    /// Value: 0 - not connected, 1 - connected.
    IS_CONNECTED,
    /// Open status (read only):
    /// 1 - camera control port open, 0 - not open.
    IS_OPEN,
    /// Camera type.
    TYPE,
    /// Camera custom param.
    CUSTOM_1,
    /// Camera custom param.
    CUSTOM_2,
    /// Camera custom param.
    CUSTOM_3
};
}

Table 3 - Camera params description.

Parameter Access Description
WIDTH read / write Not supported by OwlCamera library.
HEIGHT read / write Not supported by OwlCamera library.
DISPLAY_MODE read / write Not supported by OwlCamera library.
VIDEO_OUTPUT read / write Not supported by OwlCamera library.
LOG_MODE read / write Logging mode. Values:
0 - Disable,
1 - Only file,
2 - Only terminal (console),
3 - File and terminal.
Other values are rejected.
EXPOSURE_MODE read / write Exposure mode (ALC). Values:
0 - Manual (ALC disabled),
1 - Auto (ALC enabled).
EXPOSURE_TIME read / write Exposure time raw value. OWL 640: 1 count = 25 ns (40 MHz), range [20:1073741823]. OWL 1280 low gain: 1 count = 1 µs. OWL 1280 high gain: 1 count = 10 µs. Accepted values: from 0 up to (not including) 2^31, the camera gets the 32-bit value. The value is a float: integers above 16777216 (2^24) are not represented exactly.
WHITE_BALANCE_MODE read / write Not supported by OwlCamera library.
WHITE_BALANCE_AREA read / write Not supported by OwlCamera library.
WIDE_DYNAMIC_RANGE_MODE read / write Not supported by OwlCamera library.
STABILIZATION_MODE read / write Not supported by OwlCamera library.
ISO_SENSITIVITY read / write Not supported by OwlCamera library.
SCENE_MODE read / write Not supported by OwlCamera library.
FPS read / write Frame rate in frames per second. Internally converted to period counts (OWL 640: 40 MHz, OWL 1280: 70 MHz). The value must be a finite number greater than 0. A value for which the period doesn’t fit 32 bits (less than 70000000 / 2^32 for OWL 1280 and 40000000 / 2^32 for OWL 640) is rejected.
BRIGHTNESS_MODE read / write Not supported by OwlCamera library.
BRIGHTNESS read / write ALC level (auto level set point). 14-bit value, range [0:16383]. 0x3FFF = White.
CONTRAST read / write Not supported by OwlCamera library.
GAIN_MODE read / write Gain mode. Values:
0 - Low Gain,
1 - High Gain.
Note: gain mode cannot be set if ALC (OWL 1280) or AGMC (OWL 640) is enabled.
GAIN read / write Digital video gain. 16-bit value = gain × 256. Sent as two serial commands. Accepted values: from 0 up to (not including) 2^31, the camera gets the least significant 16 bits. Note: ALC must be disabled.
SHARPENING_MODE read / write Not supported by OwlCamera library.
SHARPENING read / write Not supported by OwlCamera library.
PALETTE read / write Not supported by OwlCamera library.
AGC_MODE read / write Automatic Gain Mode Control (OWL 640 only, AGMC). Values:
0 - Disabled,
1 - Enabled.
Not supported on OWL 1280.
SHUTTER_MODE read / write Not supported by OwlCamera library.
SHUTTER_POSITION read / write Not supported by OwlCamera library.
SHUTTER_SPEED read / write Not supported by OwlCamera library.
DIGITAL_ZOOM_MODE read / write Not supported by OwlCamera library.
DIGITAL_ZOOM read only Not supported by OwlCamera library.
EXPOSURE_COMPENSATION_MODE read only Not supported by OwlCamera library.
EXPOSURE_COMPENSATION_POSITION read / write Not supported by OwlCamera library.
DEFOG_MODE read / write Not supported by OwlCamera library.
DEHAZE_MODE read / write Not supported by OwlCamera library.
NOISE_REDUCTION_MODE read / write Not supported by OwlCamera library.
BLACK_WHITE_FILTER_MODE read only Not supported by OwlCamera library.
FILTER_MODE read / write Not supported by OwlCamera library.
NUC_MODE read / write Automatic NUC mode: 0 - Off, 1 - Offset corrected, 2 - Offset + Gain corrected, 3 - Offset + Gain + Dark corrected.
AUTO_NUC_INTERVAL_MSEC read / write Not supported by OwlCamera library.
IMAGE_FLIP read / write Image flip mode. Values:
0 - Off,
1 - Horizontal,
2 - Vertical,
3 - Horizontal and vertical.
DDE_MODE read / write Not supported by OwlCamera library.
DDE_LEVEL read / write Not supported by OwlCamera library.
ROI_X0 read / write ROI X offset. OWL 640: 8-bit value = 1/4 of X pixel offset. OWL 1280: 8-bit value = 1/8 of X pixel offset. Accepted values: from 0 up to (not including) 2^31, the camera gets the least significant 8 bits.
ROI_Y0 read / write ROI Y offset. OWL 640: 8-bit value = 1/4 of Y pixel offset. OWL 1280: 8-bit value = 1/8 of Y pixel offset. Accepted values: from 0 up to (not including) 2^31, the camera gets the least significant 8 bits.
ROI_X1 read / write ROI X size. OWL 640: 8-bit value = 1/4 of X pixel size. OWL 1280: 8-bit value = 1/8 of X pixel size. Accepted values: from 0 up to (not including) 2^31, the camera gets the least significant 8 bits.
ROI_Y1 read / write ROI Y size. OWL 640: 8-bit value = 1/4 of Y pixel size. OWL 1280: 8-bit value = 1/8 of Y pixel size. Accepted values: from 0 up to (not including) 2^31, the camera gets the least significant 8 bits.
TEMPERATURE read only Not supported by OwlCamera library.
ALC_GATE read / write Not supported by OwlCamera library.
SENSITIVITY read / write Not supported by OwlCamera library.
CHANGING_MODE read / write Not supported by OwlCamera library.
CHANGING_LEVEL read / write Not supported by OwlCamera library.
CHROMA_LEVEL read / write Not supported by OwlCamera library.
DETAIL read / write Not supported by OwlCamera library.
PROFILE read / write Not supported by OwlCamera library.
IS_CONNECTED read only Connection status. The library does not read responses of the camera: the status is 1 after the serial port is opened and after every command that was written to the serial port, and 0 if the serial port is closed or the last command was not written to the serial port. Values: 0 - not connected, 1 - connected.
IS_OPEN read only Controller initialization status. Shows if the controller is initialized or not but doesn’t show if the controller has communication with the equipment. For example, if the serial port is open but the equipment is not active (no power), the open status just shows that the controller has opened the serial port. Values: 0 - not open (not initialized), 1 - open (initialized).
TYPE read / write Camera type. The value 640 selects OWL 640, any other integer value selects OWL 1280. Initial value is 0: until the type is set the commands of OWL 640 camera are sent. initCamera(…) sets the type from the type field of CameraParams.
CUSTOM_1 read / write TEC set point. 12-bit DAC value. The value is sent as two serial commands. Accepted values: from 0 up to (not including) 2^32, the camera gets the least significant 16 bits.
CUSTOM_2 read / write Peak/Average mode. 8-bit value: 0 = Full Peak, 255 = Full Average. Accepted values: from 0 up to (not including) 2^32, the camera gets the least significant 8 bits.
CUSTOM_3 read / write AGC/ALC speed. Encoded as gainSpeed × 16 + expSpeed (both [0:15], default: 7). OWL 640 uses AGC speed, OWL 1280 uses ALC speed. Accepted values: from 0 up to (not including) 2^32, only the least significant 8 bits are used.

Example

The example below demonstrates how to use the OwlCamera library. The example shows how to initialize the camera controller, set camera parameters and execute camera commands.

#include <iostream>
#include "OwlCamera.h"

int main()
{
    // Init camera controller.
    rapidpixel::OwlCamera camera;
    if (!camera.openCamera("/dev/ttyUSB0"))
    {
        std::cout << "Camera controller initialization failed." << std::endl;
        return 1;
    }

    // Select the camera type (OWL 640).
    if (!camera.setParam(rapidpixel::CameraParam::TYPE, 640.0f))
    {
        std::cout << "Can't set camera type." << std::endl;
        return 1;
    }

    // Set camera parameters. Enable logging to the terminal.
    if (!camera.setParam(rapidpixel::CameraParam::LOG_MODE, 2.0f))
    {
        std::cout << "Can't set log mode." << std::endl;
        return 1;
    }

    // Execute camera command. Restart the camera.
    if (!camera.executeCommand(rapidpixel::CameraCommand::RESTART))
    {
        std::cout << "Can't execute command." << std::endl;
        return 1;
    }

    return 0;
}

CameraParams class description

CameraParams class used for camera controller initialization or to get all actual params. Also CameraParams provide structure to write/read params from JSON files (JSON_READABLE macro) and provide method to encode and decode params.

CameraParams Class declaration

CameraParams interface class declared in Camera.h file. Class declaration:

namespace rapidpixel
{
class CameraParams
{
public:
    /// Initialization string.
    std::string initString{"/dev/ttyUSB0;9600;20"};
    /// Video frame width. Value from 0 to 16384.
    int width{0};
    /// Video frame height Value from 0 to 16384.
    int height{0};
    /// Display menu mode. 
    int displayMode{0};
    /// Video output type.
    int videoOutput{0};
    /// Logging mode.
    int logMode{0};
    /// Exposure mode. 
    int exposureMode{1};
    /// Exposure time of the camera sensor.
    int exposureTime{0};
    /// White balance mode. 
    int whiteBalanceMode{1};
    /// White balance area.
    int whiteBalanceArea{0};
    /// White dynamic range mode.
    int wideDynamicRangeMode{0};
    /// Image stabilization mode.
    int stabilizationMode{0};
    /// ISO sensitivity.
    int isoSensitivity{0};
    /// Scene mode.
    int sceneMode{0};
    /// FPS.
    float fps{0.0f};
    /// Brightness mode.
    int brightnessMode{1};
    /// Brightness. Value 0 - 100%.
    int brightness{0};
    /// Contrast. Value 1 - 100%.
    int contrast{0};
    /// Gain mode.
    int gainMode{1};
    /// Gain. Value 1 - 100%.
    int gain{0};
    /// Sharpening mode.
    int sharpeningMode{0};
    /// Sharpening. Value 1 - 100%.
    int sharpening{0};
    /// Palette.
    int palette{0};
    /// Analog gain control mode.
    int agcMode{1};
    /// Shutter mode.
    int shutterMode{1};
    /// Shutter position. 0 (full close) - 65535 (full open).
    int shutterPos{0};
    /// Shutter speed. Value: 0 - 100%.
    int shutterSpeed{0};
    /// Digital zoom mode.
    int digitalZoomMode{0};
    /// Digital zoom. Value 1.0 (x1) - 20.0 (x20).
    float digitalZoom{1.0f};
    /// Exposure compensation mode.
    int exposureCompensationMode{0};
    /// Exposure compensation position.
    int exposureCompensationPosition{0};
    /// Defog mode. 
    int defogMode{0};
    /// Dehaze mode.
    int dehazeMode{0};
    /// Noise reduction mode.
    int noiseReductionMode{0};
    /// Black and white filter mode.
    int blackAndWhiteFilterMode{0};
    /// Filter mode.
    int filterMode{0};
    /// NUC mode for thermal cameras.
    int nucMode{0};
    /// Auto NUC interval for thermal cameras.
    int autoNucIntervalMsec{0};
    /// Image flip mode. 
    int imageFlip{0};
    /// DDE mode.
    int ddeMode{0};
    /// DDE level.
    float ddeLevel{0};
    /// ROI top-left horizontal position, pixels.
    int roiX0{0};
    /// ROI top-left vertical position, pixels.
    int roiY0{0};
    /// ROI bottom-right horizontal position, pixels.
    int roiX1{0};
    /// ROI bottom-right vertical position, pixels.
    int roiY1{0};
    /// Camera temperature, degree.
    float temperature{0.0f};
    /// ALC gate.
    int alcGate{0};
    /// Sensor sensitivity.
    float sensitivity{0};
    /// Changing mode (day / night).
    int changingMode{0};
    /// Changing level (day / night).
    float changingLevel{0.0f};
    /// Chroma level. Values: 0 - 100%.
    int chromaLevel{0};
    /// Details, enhancement. Values: 0 - 100%.
    int detail{0};
    /// Camera settings profile.
    int profile{0};
    /// Connection status (read only).
    bool isConnected{false};
    /// Open status (read only).
    bool isOpen{false};
    /// Camera type.
    int type{0};
    /// Camera custom param.
    float custom1{0.0f};
    /// Camera custom param.
    float custom2{0.0f};
    /// Camera custom param.
    float custom3{0.0f};

    JSON_READABLE(CameraParams, initString, width, height, displayMode,
                  videoOutput, logMode, exposureMode, exposureTime,
                  whiteBalanceMode, whiteBalanceArea, wideDynamicRangeMode,
                  stabilizationMode, isoSensitivity, sceneMode, fps,
                  brightnessMode, brightness, contrast, gainMode, gain,
                  sharpeningMode, sharpening, palette, agcMode, shutterMode,
                  shutterPos, shutterSpeed, digitalZoomMode, digitalZoom,
                  exposureCompensationMode, exposureCompensationPosition,
                  defogMode, dehazeMode, noiseReductionMode,
                  blackAndWhiteFilterMode, filterMode, nucMode,
                  autoNucIntervalMsec, imageFlip, ddeMode, ddeLevel,
                  roiX0, roiY0, roiX1, roiY1, alcGate, sensitivity,
                  changingMode, changingLevel, chromaLevel, detail,
                  profile, type, custom1, custom2, custom3)

    /// operator =
    CameraParams& operator= (const CameraParams& src);

    /// Encode params. The method doesn't encode initString.
    bool encode(uint8_t* data, int bufferSize, int& size,
                CameraParamsMask* mask = nullptr);

    /// Decode params. The method doesn't decode initString.
    bool decode(uint8_t* data, int dataSize);
};
}

Table 4 - CameraParams class fields description is equivalent to CameraParam enum description.

Field type Description
initString string Initialization string. The first non-empty segment before ‘;’ is the serial port name, or the whole string if there is no ‘;’. The baudrate is always 115200.
width int Not supported by OwlCamera library.
height int Not supported by OwlCamera library.
displayMode int Not supported by OwlCamera library.
videoOutput int Not supported by OwlCamera library.
logMode int Logging mode. Values:
0 - Disable
1 - Only file
2 - Only terminal (console)
3 - File and terminal
exposureMode int Exposure mode (ALC). 0 - Manual (ALC disabled), 1 - Auto (ALC enabled).
exposureTime int Exposure time raw value. OWL 640: 1 count = 25 ns. OWL 1280 low gain: 1 count = 1 µs. OWL 1280 high gain: 1 count = 10 µs.
whiteBalanceMode int Not supported by OwlCamera library.
whiteBalanceArea int Not supported by OwlCamera library.
wideDynamicRangeMode int Not supported by OwlCamera library.
stabilizationMode int Not supported by OwlCamera library.
isoSensitivity int Not supported by OwlCamera library.
sceneMode int Not supported by OwlCamera library.
fps float Frame rate (frames per second). Converted to period counts internally.
brightnessMode int Not supported by OwlCamera library.
brightness int ALC level (auto level set point). 14-bit value, range [0:16383].
contrast int Not supported by OwlCamera library.
gainMode int Gain mode. 0 - Low Gain, 1 - High Gain.
gain int Digital video gain. 16-bit value = gain × 256.
sharpeningMode int Not supported by OwlCamera library.
sharpening int Not supported by OwlCamera library.
palette int Not supported by OwlCamera library.
agcMode int Automatic Gain Mode Control (OWL 640 only, AGMC). 0 - Disabled, 1 - Enabled.
shutterMode int Not supported by OwlCamera library.
shutterPos int Not supported by OwlCamera library.
shutterSpeed int Not supported by OwlCamera library.
digitalZoomMode int Not supported by OwlCamera library.
digitalZoom float Not supported by OwlCamera library.
exposureCompensationMode int Not supported by OwlCamera library.
exposureCompensationPosition int Not supported by OwlCamera library.
defogMode int Not supported by OwlCamera library.
dehazeMode int Not supported by OwlCamera library.
noiseReductionMode int Not supported by OwlCamera library.
blackAndWhiteFilterMode int Not supported by OwlCamera library.
filterMode int Not supported by OwlCamera library.
nucMode int NUC mode: 0 - Off, 1 - Offset corrected, 2 - Offset + Gain corrected, 3 - Offset + Gain + Dark corrected.
autoNucIntervalMsec int Not supported by OwlCamera library.
imageFlip int Image flip mode. 0 - Off, 1 - Horizontal, 2 - Vertical, 3 - Horizontal and vertical.
ddeMode int Not supported by OwlCamera library.
ddeLevel float Not supported by OwlCamera library.
roiX0 int ROI X offset. OWL 640: 1/4 pixel. OWL 1280: 1/8 pixel.
roiY0 int ROI Y offset. OWL 640: 1/4 pixel. OWL 1280: 1/8 pixel.
roiX1 int ROI X size. OWL 640: 1/4 pixel. OWL 1280: 1/8 pixel.
roiY1 int ROI Y size. OWL 640: 1/4 pixel. OWL 1280: 1/8 pixel.
temperature float Not supported by OwlCamera library.
alcGate int Not supported by OwlCamera library.
sensitivity float Not supported by OwlCamera library.
changingMode int Not supported by OwlCamera library.
changingLevel float Not supported by OwlCamera library.
chromaLevel int Not supported by OwlCamera library.
detail int Not supported by OwlCamera library.
profile int Not supported by OwlCamera library.
isConnected bool Connection status. Shows if the last command was written to the serial port (see IS_CONNECTED). Values: 0 - not connected, 1 - connected.
isOpen bool Controller initialization status. Shows if the controller is initialized. Values: 0 - not open, 1 - open.
type int Camera type. 640 (OWL 640) or any other value for OWL 1280. Initial value is 0: the commands of OWL 640 camera are sent until the type is set.
custom1 float TEC set point. 12-bit DAC value.
custom2 float Peak/Average mode. 8-bit value: 0 = Full Peak, 255 = Full Average.
custom3 float AGC/ALC speed. Encoded as gainSpeed × 16 + expSpeed (both [0:15]).

Note: CameraParams class fields listed above reflect params set/get by methods setParam(…) and getParam(…).

Serialize camera params

CameraParams class provides the encode(…) method to serialize camera params (fields of CameraParams class, see Table 4). Serialization of camera params is necessary when you have to send camera params via communication channels. The method doesn’t encode the initString field. The method provides options to exclude particular parameters from serialization. To do this, the method inserts a binary mask (8 bytes) where each bit represents a particular parameter and the decode(…) method recognizes it. Method declaration:

bool encode(uint8_t* data, int bufferSize, int& size, CameraParamsMask* mask = nullptr);
Parameter Value
data Pointer to data buffer. Buffer size must be >= 237 bytes.
bufferSize Data buffer size. Buffer size must be >= 237 bytes.
size Size of encoded data.
mask Parameters mask - pointer to CameraParamsMask structure. CameraParamsMask (declared in Camera.h file) determines flags for each field (parameter) declared in CameraParams class. If the user wants to exclude any parameters from serialization, he can put a pointer to the mask. If the user wants to exclude a particular parameter from serialization, he should set the corresponding flag in the CameraParamsMask structure.

Returns: TRUE if params encoded (serialized) or FALSE if not.

CameraParamsMask structure declaration:

typedef struct CameraParamsMask
{
    bool width{true};
    bool height{true};
    bool displayMode{true};
    bool videoOutput{true};
    bool logMode{true};
    bool exposureMode{true};
    bool exposureTime{true};
    bool whiteBalanceMode{true};
    bool whiteBalanceArea{true};
    bool wideDynamicRangeMode{true};
    bool stabilizationMode{true};
    bool isoSensitivity{true};
    bool sceneMode{true};
    bool fps{true};
    bool brightnessMode{true};
    bool brightness{true};
    bool contrast{true};
    bool gainMode{true};
    bool gain{true};
    bool sharpeningMode{true};
    bool sharpening{true};
    bool palette{true};
    bool agcMode{true};
    bool shutterMode{true};
    bool shutterPos{true};
    bool shutterSpeed{true};
    bool digitalZoomMode{true};
    bool digitalZoom{true};
    bool exposureCompensationMode{true};
    bool exposureCompensationPosition{true};
    bool defogMode{true};
    bool dehazeMode{true};
    bool noiseReductionMode{true};
    bool blackAndWhiteFilterMode{true};
    bool filterMode{true};
    bool nucMode{true};
    bool autoNucIntervalMsec{true};
    bool imageFlip{true};
    bool ddeMode{true};
    bool ddeLevel{true};
    bool roiX0{true};
    bool roiY0{true};
    bool roiX1{true};
    bool roiY1{true};
    bool temperature{true};
    bool alcGate{true};
    bool sensitivity{true};
    bool changingMode{true};
    bool changingLevel{true};
    bool chromaLevel{true};
    bool detail{true};
    bool profile{true};
    bool isConnected{true};
    bool isOpen{true};
    bool type{true};
    bool custom1{true};
    bool custom2{true};
    bool custom3{true};
} CameraParamsMask;

Example without parameters mask:

// Encode data.
rapidpixel::CameraParams in;
in.profile = 10;
uint8_t data[1024];
int size = 0;
if (!in.encode(data, 1024, size))
{
    std::cout << "Can't encode data" << std::endl;
    return false;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;

Example with parameters mask:

// Prepare params.
rapidpixel::CameraParams in;
in.profile = 3;

// Prepare mask.
rapidpixel::CameraParamsMask mask;
mask.profile = false; // Exclude profile. Others by default.

// Encode.
uint8_t data[1024];
int size = 0;
if (!in.encode(data, 1024, size, &mask))
{
    std::cout << "Can't encode data" << std::endl;
    return false;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;

Deserialize camera params

CameraParams class provides the decode(…) method to deserialize camera params (fields of CameraParams class, see Table 4). Deserialization of camera params is necessary when you need to receive params via communication channels. The method automatically recognizes which parameters were serialized by the encode(…) method. The method doesn’t decode the initString field. Method declaration:

bool decode(uint8_t* data, int dataSize);
Parameter Value
data Pointer to data buffer with serialized camera params.
dataSize Size of command data.

Returns: TRUE if params decoded (deserialized) or FALSE if not.

Example:

// Encode data.
rapidpixel::CameraParams in;
uint8_t data[1024];
int size = 0;
if (!in.encode(data, 1024, size))
{
    std::cout << "Can't encode data" << std::endl;
    return false;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;

// Decode data.
rapidpixel::CameraParams out;
if (!out.decode(data, size))
{
    std::cout << "Can't decode data" << std::endl;
    return false;
}

Read and write camera params to JSON file

Camera library depends on ConfigReader library which provides methods to read params from JSON file and to write params to JSON file. Example of writing and reading params to JSON file:

// Write params to file.
rapidpixel::CameraParams in;
rapidpixel::ConfigReader inConfig;
if (!inConfig.set(in, "cameraParams") ||
    !inConfig.writeToFile("TestCameraParams.json"))
{
    std::cout << "Can't write config file" << std::endl;
    return false;
}

// Read params from file.
rapidpixel::ConfigReader outConfig;
if (!outConfig.readFromFile("TestCameraParams.json"))
{
    std::cout << "Can't open config file" << std::endl;
    return false;
}
rapidpixel::CameraParams out;
if (!outConfig.get(out, "cameraParams"))
{
    std::cout << "Can't read params" << std::endl;
    return false;
}

TestCameraParams.json will look like (the params are default values of the CameraParams class):

{
    "cameraParams": {
        "initString": "/dev/ttyUSB0;9600;20",
        "width": 0,
        "height": 0,
        "displayMode": 0,
        "videoOutput": 0,
        "logMode": 0,
        "exposureMode": 1,
        "exposureTime": 0,
        "whiteBalanceMode": 1,
        "whiteBalanceArea": 0,
        "wideDynamicRangeMode": 0,
        "stabilizationMode": 0,
        "isoSensitivity": 0,
        "sceneMode": 0,
        "fps": 0.0,
        "brightnessMode": 1,
        "brightness": 0,
        "contrast": 0,
        "gainMode": 1,
        "gain": 0,
        "sharpeningMode": 0,
        "sharpening": 0,
        "palette": 0,
        "agcMode": 1,
        "shutterMode": 1,
        "shutterPos": 0,
        "shutterSpeed": 0,
        "digitalZoomMode": 0,
        "digitalZoom": 1.0,
        "exposureCompensationMode": 0,
        "exposureCompensationPosition": 0,
        "defogMode": 0,
        "dehazeMode": 0,
        "noiseReductionMode": 0,
        "blackAndWhiteFilterMode": 0,
        "filterMode": 0,
        "nucMode": 0,
        "autoNucIntervalMsec": 0,
        "imageFlip": 0,
        "ddeMode": 0,
        "ddeLevel": 0.0,
        "roiX0": 0,
        "roiY0": 0,
        "roiX1": 0,
        "roiY1": 0,
        "alcGate": 0,
        "sensitivity": 0.0,
        "changingMode": 0,
        "changingLevel": 0.0,
        "chromaLevel": 0,
        "detail": 0,
        "profile": 0,
        "type": 0,
        "custom1": 0.0,
        "custom2": 0.0,
        "custom3": 0.0
    }
}

Build and connect to your project

Build stand alone

The repository does not contain sub-repositories. The protocol parser library OwlParser is a part of the repository (folder src/parser, see src/parser/README.md): the main CMakeLists.txt file of the library adds it before the library itself in every build (stand alone and included in another project), so it is not cloned and not added separately; its test application (src/parser/test) is not built. The other libraries OwlCamera depends on (ConfigReader, Camera, SerialPort and Logger) must be cloned into the same folder as OwlCamera. The folder structure must be:

<work folder>
    OwlCamera
    ConfigReader
    Camera
    SerialPort
    Logger

Typical commands to build the library and the test application (use the URLs of the repositories provided to you):

git clone <OwlCamera repository URL>
git clone <ConfigReader repository URL>
git clone <Camera repository URL>
git clone <SerialPort repository URL>
git clone <Logger repository URL>
cd OwlCamera
mkdir build
cd build
cmake ..
make

On Windows use cmake --build . --config Release instead of make. If OwlCamera is the top-level CMake project, the main CMakeLists.txt file adds the folders ../ConfigReader, ../Camera, ../SerialPort and ../Logger (in this order) before the library itself. If a folder does not exist CMake stops with an error.

CMake options

Table 5 - CMake options of the repository. In the options below ${PARENT} is the prefix defined by the top-level project (empty if OwlCamera is the top-level project).

Option Default Description
${PARENT}_OWL_CAMERA ON Build the library.
${PARENT}_OWL_CAMERA_TEST ON (stand alone), OFF (included in other project) Build the test application.
${PARENT}_SUBMODULE_CACHE_OVERWRITE ON Forced rewriting of the options above in the CMake cache. The top-level project sets it to OFF when it includes OwlCamera as a sub-repository.
CMAKE_BUILD_TYPE Release (if not specified) Build type.

Connect to your project

If you want connect OwlCamera library to your CMake project as source code you can make the following. For example, if your repository has structure:

CMakeLists.txt
src
    CMakeList.txt
    yourLib.h
    yourLib.cpp

Create folder 3rdparty and copy there the folders of the OwlCamera repository and of the repositories it depends on (ConfigReader, Camera, SerialPort and Logger). OwlCamera does not add its dependencies when it is included in another project: your project must add them. Structure of your repository:

CMakeLists.txt
src
    CMakeList.txt
    yourLib.h
    yourLib.cpp
3rdparty
    OwlCamera
    ConfigReader
    Camera
    SerialPort
    Logger

Create CMakeLists.txt file in 3rdparty folder. CMakeLists.txt should contain:

cmake_minimum_required(VERSION 3.13)

################################################################################
## 3RD-PARTY
## dependencies for the project
################################################################################
project(3rdparty LANGUAGES CXX)

################################################################################
## SETTINGS
## basic 3rd-party settings before use
################################################################################
# To inherit the top-level architecture when the project is used as a submodule.
SET(PARENT ${PARENT}_YOUR_PROJECT_3RDPARTY)
# Disable self-overwriting of parameters inside included subdirectories.
SET(${PARENT}_SUBMODULE_CACHE_OVERWRITE OFF CACHE BOOL "" FORCE)

################################################################################
## CONFIGURATION
## 3rd-party submodules configuration
################################################################################
SET(${PARENT}_SUBMODULE_CONFIG_READER                   ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_CONFIG_READER)
    SET(${PARENT}_CONFIG_READER                         ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_CONFIG_READER_EXAMPLES                OFF CACHE BOOL "" FORCE)
    SET(${PARENT}_CONFIG_READER_TESTS                   OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_CAMERA                          ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_CAMERA)
    SET(${PARENT}_CAMERA                                ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_CAMERA_TEST                           OFF CACHE BOOL "" FORCE)
    SET(${PARENT}_CAMERA_EXAMPLE                        OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_SERIAL_PORT                     ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_SERIAL_PORT)
    SET(${PARENT}_SERIAL_PORT                           ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_SERIAL_PORT_EXAMPLES                  OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_LOGGER                          ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_LOGGER)
    SET(${PARENT}_LOGGER                                ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_LOGGER_EXAMPLE                        OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_OWL_CAMERA                      ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_OWL_CAMERA)
    SET(${PARENT}_OWL_CAMERA                            ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_OWL_CAMERA_TEST                       OFF CACHE BOOL "" FORCE)
endif()

################################################################################
## INCLUDING SUBDIRECTORIES
## Adding subdirectories according to the 3rd-party configuration
################################################################################
if (${PARENT}_SUBMODULE_CONFIG_READER)
    add_subdirectory(ConfigReader)
endif()

if (${PARENT}_SUBMODULE_CAMERA)
    add_subdirectory(Camera)
endif()

if (${PARENT}_SUBMODULE_SERIAL_PORT)
    add_subdirectory(SerialPort)
endif()

if (${PARENT}_SUBMODULE_LOGGER)
    add_subdirectory(Logger)
endif()

if (${PARENT}_SUBMODULE_OWL_CAMERA)
    add_subdirectory(OwlCamera)
endif()

File 3rdparty/CMakeLists.txt adds the folders of the libraries in the order of their mutual dependencies and then the folder OwlCamera to your project. If a library is not added the compilation stops with an error (for example “SerialPort.h: No such file or directory”). Structure of your repository with the CMake file:

CMakeLists.txt
src
    CMakeList.txt
    yourLib.h
    yourLib.cpp
3rdparty
    CMakeLists.txt
    OwlCamera
    ConfigReader
    Camera
    SerialPort
    Logger

Next you need include folder 3rdparty in main CMakeLists.txt file of your repository. Add string at the end of your main CMakeLists.txt:

add_subdirectory(3rdparty)

Next you have to include OwlCamera library in your src/CMakeLists.txt file:

target_link_libraries(${PROJECT_NAME} OwlCamera)

Done!

Portability

The library has no processor specific code (no SIMD instructions and no inline assembler) and is built with GCC for x86-64 and AArch64 (Linux). The bytes of the commands which are sent to the camera are composed by explicit shifts, so they do not depend on the byte order of the host. The integer and float fields of the messages decoded by the decodeAndExecuteCommand(…) method are read in the byte order of the host (format of the Camera library): the control system and the controller must have the same byte order.

Test application

The repository includes a test application (test/main.cpp) to control the camera parameters and to execute the camera commands from the terminal. The application sends the commands to the camera via a serial port. It doesn’t open any window, doesn’t show video and doesn’t write any file. To build and run the test application:

cd OwlCamera
mkdir build
cd build
cmake ..
make
./bin/OwlCameraTest

The application can get the serial port name and the camera type as arguments (for example ./bin/OwlCameraTest /dev/ttyUSB0 1280). Without arguments the application asks for them:

OwlCamera version: 3.1.0
Enter serial port name: /dev/ttyUSB0
Choose camera type (640 or 1280): 1280
Camera opened successfully.

After initialization, the application presents the menu:

-------------------------------------------
Choose command:
0 - Exit
1 - Restart camera
2 - NUC command (set NUC mode to 4)
3 - NUC mode
4 - Exposure mode
5 - Exposure time
6 - Gain mode
7 - Gain
8 - Image flip mode
9 - FPS
10 - AGC mode
11 - Brightness (ALC level)
12 - Custom param 1 (TEC set point)
13 - Custom param 2 (Peak/Average)
14 - Custom param 3 (AGC/ALC speed)
15 - ROI X offset
16 - ROI Y offset
17 - ROI X size
18 - ROI Y size
19 - Print camera params
20 - Log mode (0 - Off, 1 - File, 2 - Console, 3 - File and console)
Your option:

The application reads the option and the values line by line. A line that is not a number is rejected (“Invalid option.” or “Invalid number.”) and the menu is shown again. The result of every command is printed (for example “Set gain: OK.” or “Can’t set gain.”). The application exits by the option 0 or when the input is closed. The exit code is 0, or 1 if the arguments are wrong or the camera can’t be opened.


Table of contents