MYNT-EYE-S-SDK/include/mynteye/types.h

563 lines
13 KiB
C
Raw Normal View History

2018-05-10 09:46:34 +03:00
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2018-10-27 16:24:04 +03:00
#ifndef MYNTEYE_TYPES_H_
2018-04-03 05:27:28 +03:00
#define MYNTEYE_TYPES_H_
#pragma once
#include <cstdint>
2018-04-08 17:35:49 +03:00
#include <algorithm>
2018-04-03 05:27:28 +03:00
#include <iostream>
#include <type_traits>
#include "mynteye/mynteye.h"
MYNTEYE_BEGIN_NAMESPACE
2018-04-03 18:27:17 +03:00
/**
* @defgroup enumerations Enumerations
* @brief Public enumeration types.
*/
2018-04-04 10:52:10 +03:00
/**
* @ingroup enumerations
* @brief Device model.
*/
enum class Model : std::uint8_t {
/** Standard */
STANDARD,
/** Standard 2 generation */
STANDARD2,
2018-04-04 10:52:10 +03:00
/** Last guard */
LAST
};
2018-04-03 05:27:28 +03:00
/**
* @ingroup enumerations
* @brief Streams define different type of data.
*/
enum class Stream : std::uint8_t {
/** Left stream */
LEFT,
/** Right stream */
RIGHT,
/** Left stream, rectified */
LEFT_RECTIFIED,
/** Right stream, rectified */
RIGHT_RECTIFIED,
/** Disparity stream */
DISPARITY,
/** Disparity stream, normalized */
DISPARITY_NORMALIZED,
/** Depth stream */
DEPTH,
/** Point cloud stream */
POINTS,
/** Last guard */
LAST
};
/**
* @ingroup enumerations
* @brief Capabilities define the full set of functionality that the device
* might provide.
*/
enum class Capabilities : std::uint8_t {
2018-05-16 05:31:31 +03:00
/** Provides stereo stream */
2018-04-03 05:27:28 +03:00
STEREO,
/** Provide stereo color stream */
STEREO_COLOR,
2018-05-16 05:31:31 +03:00
/** Provides color stream */
2018-04-03 05:27:28 +03:00
COLOR,
2018-05-16 05:31:31 +03:00
/** Provides depth stream */
2018-04-03 05:27:28 +03:00
DEPTH,
2018-05-16 05:31:31 +03:00
/** Provides point cloud stream */
2018-04-03 05:27:28 +03:00
POINTS,
2018-05-16 05:31:31 +03:00
/** Provides fisheye stream */
2018-04-03 05:27:28 +03:00
FISHEYE,
2018-05-16 05:31:31 +03:00
/** Provides infrared stream */
2018-04-03 08:53:32 +03:00
INFRARED,
2018-05-16 05:31:31 +03:00
/** Provides second infrared stream */
2018-04-03 08:53:32 +03:00
INFRARED2,
2018-05-16 05:31:31 +03:00
/** Provides IMU (accelerometer, gyroscope) data */
2018-04-03 05:27:28 +03:00
IMU,
/** Last guard */
LAST
};
/**
* @ingroup enumerations
* @brief Camera info fields are read-only strings that can be queried from the
* device.
*/
enum class Info : std::uint8_t {
/** Device name */
DEVICE_NAME,
/** Serial number */
SERIAL_NUMBER,
/** Firmware version */
FIRMWARE_VERSION,
/** Hardware version */
HARDWARE_VERSION,
/** Spec version */
SPEC_VERSION,
/** Lens type */
LENS_TYPE,
/** IMU type */
IMU_TYPE,
/** Nominal baseline */
NOMINAL_BASELINE,
/** Last guard */
2018-04-06 04:12:09 +03:00
LAST
2018-04-03 05:27:28 +03:00
};
/**
* @ingroup enumerations
2018-04-03 18:27:17 +03:00
* @brief Camera control options define general configuration controls.
2018-04-03 05:27:28 +03:00
*/
enum class Option : std::uint8_t {
2018-05-16 05:31:31 +03:00
/**
* Image gain, valid if manual-exposure
*
* range: [0,48], default: 24
*/
2018-04-03 05:27:28 +03:00
GAIN,
2018-05-16 05:31:31 +03:00
/**
* Image brightness, valid if manual-exposure
*
* range: [0,240], default: 120
*/
2018-04-03 05:27:28 +03:00
BRIGHTNESS,
2018-05-16 05:31:31 +03:00
/**
* Image contrast, valid if manual-exposure
*
* range: [0,255], default: 127
*/
2018-04-03 05:27:28 +03:00
CONTRAST,
2018-05-16 05:31:31 +03:00
/**
* Image frame rate, must set IMU_FREQUENCY together
*
* values: {10,15,20,25,30,35,40,45,50,55,60}, default: 25
*/
2018-04-03 05:27:28 +03:00
FRAME_RATE,
2018-05-16 05:31:31 +03:00
/**
* IMU frequency, must set FRAME_RATE together
*
* values: {100,200,250,333,500}, default: 200
*/
2018-04-03 05:27:28 +03:00
IMU_FREQUENCY,
2018-04-03 05:27:28 +03:00
/**
* Exposure mode
*
* 0: enable auto-exposure
* 1: disable auto-exposure (manual-exposure)
*/
EXPOSURE_MODE,
2018-05-16 05:31:31 +03:00
/**
* Max gain, valid if auto-exposure
*
2018-11-27 12:00:22 +02:00
* range: [0,255], default: 8
2018-05-16 05:31:31 +03:00
*/
2018-04-03 05:27:28 +03:00
MAX_GAIN,
2018-05-16 05:31:31 +03:00
/**
* Max exposure time, valid if auto-exposure
*
2018-11-27 12:00:22 +02:00
* range: [0,1000], default: 333
2018-05-16 05:31:31 +03:00
*/
2018-04-03 05:27:28 +03:00
MAX_EXPOSURE_TIME,
/**
* min exposure time, valid if auto-exposure
*
* range: [0,1000], default: 0
*/
MIN_EXPOSURE_TIME,
2018-05-16 05:31:31 +03:00
/**
* Desired brightness, valid if auto-exposure
*
2018-11-27 12:00:22 +02:00
* range: [1,255], default: 122
2018-05-16 05:31:31 +03:00
*/
2018-04-03 05:27:28 +03:00
DESIRED_BRIGHTNESS,
2018-05-16 05:31:31 +03:00
/**
* IR control
*
* range: [0,160], default: 0
*/
2018-04-03 05:27:28 +03:00
IR_CONTROL,
/**
* HDR mode
*
* 0: 10-bit
* 1: 12-bit
*/
HDR_MODE,
2018-08-16 14:34:01 +03:00
/**
* The range of accelerometer
*
2018-11-20 13:13:41 +02:00
* values: {6,12,24,48}, default: 6
2018-08-16 14:34:01 +03:00
*/
ACCELEROMETER_RANGE,
/**
* The range of gyroscope
*
2018-11-20 13:13:41 +02:00
* values: {250,500,1000,2000,4000}, default: 1000
2018-08-16 14:34:01 +03:00
*/
GYROSCOPE_RANGE,
/**
* The parameter of accelerometer low pass filter
*
2018-11-20 13:13:41 +02:00
* values: {0,1,2}, default: 2
2018-08-16 14:34:01 +03:00
*/
ACCELEROMETER_LOW_PASS_FILTER,
/**
* The parameter of gyroscope low pass filter
*
2018-11-20 13:13:41 +02:00
* values: {23,64}, default: 64
2018-08-16 14:34:01 +03:00
*/
GYROSCOPE_LOW_PASS_FILTER,
/** Zero drift calibration */
ZERO_DRIFT_CALIBRATION,
/** Erase chip */
ERASE_CHIP,
2018-04-03 05:27:28 +03:00
/** Last guard */
2018-04-06 04:12:09 +03:00
LAST
2018-04-03 05:27:28 +03:00
};
2018-04-07 04:36:41 +03:00
/**
* @ingroup enumerations
* @brief Source allows the user to choose which data to be captured.
*/
enum class Source : std::uint8_t {
/** Video streaming of stereo, color, depth, etc. */
VIDEO_STREAMING,
/** Motion tracking of IMU (accelerometer, gyroscope) */
MOTION_TRACKING,
/** Enable everything together */
ALL,
/** Last guard */
LAST
};
2018-05-04 08:44:13 +03:00
/**
* @ingroup enumerations
* @brief Add-Ons are peripheral modules of our hardware.
*/
enum class AddOns : std::uint8_t {
/** Infrared */
INFRARED,
/** Second infrared */
INFRARED2,
/** Last guard */
LAST
};
2018-04-03 05:27:28 +03:00
#define MYNTEYE_ENUM_HELPERS(TYPE) \
2018-04-23 18:11:11 +03:00
MYNTEYE_API const char *to_string(const TYPE &value); \
2018-04-03 05:27:28 +03:00
inline bool is_valid(const TYPE &value) { \
using utype = std::underlying_type<TYPE>::type; \
utype val = static_cast<utype>(value); \
utype max = static_cast<utype>(TYPE::LAST); \
return /*val >= 0 &&*/ val < max; \
} \
inline std::ostream &operator<<(std::ostream &os, const TYPE &value) { \
using utype = std::underlying_type<TYPE>::type; \
if (is_valid(value)) \
return os << to_string(value); \
else \
return os << static_cast<utype>(value); \
}
2018-04-04 10:52:10 +03:00
MYNTEYE_ENUM_HELPERS(Model)
2018-04-03 05:27:28 +03:00
MYNTEYE_ENUM_HELPERS(Stream)
MYNTEYE_ENUM_HELPERS(Capabilities)
MYNTEYE_ENUM_HELPERS(Info)
MYNTEYE_ENUM_HELPERS(Option)
2018-04-07 04:36:41 +03:00
MYNTEYE_ENUM_HELPERS(Source)
2018-05-04 08:44:13 +03:00
MYNTEYE_ENUM_HELPERS(AddOns)
2018-04-03 05:27:28 +03:00
#undef MYNTEYE_ENUM_HELPERS
2018-04-06 04:12:09 +03:00
#define MYNTEYE_FOURCC(a, b, c, d) \
((std::uint32_t)(a) | ((std::uint32_t)(b) << 8) | \
((std::uint32_t)(c) << 16) | ((std::uint32_t)(d) << 24)) // NOLINT
/**
* @ingroup enumerations
* @brief Formats define how each stream can be encoded.
*/
enum class Format : std::uint32_t {
2018-04-08 17:35:49 +03:00
/** Greyscale, 8 bits per pixel */
GREY = MYNTEYE_FOURCC('G', 'R', 'E', 'Y'),
2018-04-06 04:12:09 +03:00
/** YUV 4:2:2, 16 bits per pixel */
YUYV = MYNTEYE_FOURCC('Y', 'U', 'Y', 'V'),
2018-08-06 21:29:07 +03:00
/** BGR 8:8:8, 24 bits per pixel */
BGR888 = MYNTEYE_FOURCC('B', 'G', 'R', '3'),
2018-04-06 04:12:09 +03:00
/** Last guard */
LAST
};
#undef MYNTEYE_FOURCC
2018-04-23 18:11:11 +03:00
MYNTEYE_API const char *to_string(const Format &value);
2018-04-06 04:12:09 +03:00
inline std::ostream &operator<<(std::ostream &os, const Format &value) {
return os << to_string(value);
}
2018-04-23 18:11:11 +03:00
MYNTEYE_API std::size_t bytes_per_pixel(const Format &value);
2018-04-08 07:23:33 +03:00
/**
* Resolution.
*/
struct MYNTEYE_API Resolution {
/** Width */
std::uint16_t width;
/** Height */
std::uint16_t height;
bool operator==(const Resolution &other) const {
return width == other.width && height == other.height;
}
bool operator!=(const Resolution &other) const {
return !(*this == other);
}
bool operator<(const Resolution &other) const {
return (width * height) < (other.width * other.height);
}
};
2018-04-06 04:12:09 +03:00
/**
* Stream request.
*/
struct MYNTEYE_API StreamRequest {
2018-05-16 05:31:31 +03:00
/** Stream width in pixels */
2018-04-06 04:12:09 +03:00
std::uint16_t width;
2018-05-16 05:31:31 +03:00
/** Stream height in pixels */
2018-04-06 04:12:09 +03:00
std::uint16_t height;
2018-05-16 05:31:31 +03:00
/** Stream pixel format */
2018-04-06 04:12:09 +03:00
Format format;
2018-05-16 05:31:31 +03:00
/** Stream frames per second (unused) */
2018-04-06 04:12:09 +03:00
std::uint16_t fps;
2018-04-08 07:23:33 +03:00
StreamRequest() {}
StreamRequest(
std::uint16_t width, std::uint16_t height, Format format,
std::uint16_t fps)
: width(width), height(height), format(format), fps(fps) {}
StreamRequest(const Resolution &res, Format format, std::uint16_t fps)
: width(res.width), height(res.height), format(format), fps(fps) {}
Resolution GetResolution() const { return {width, height}; }
2018-04-08 07:23:33 +03:00
bool operator==(const StreamRequest &other) const {
return width == other.width && height == other.height &&
format == other.format && fps == other.fps;
}
bool operator!=(const StreamRequest &other) const {
return !(*this == other);
}
2018-04-06 04:12:09 +03:00
};
2018-04-23 18:11:11 +03:00
MYNTEYE_API
2018-04-08 17:35:49 +03:00
std::ostream &operator<<(std::ostream &os, const StreamRequest &request);
2018-04-03 18:27:17 +03:00
/**
* @defgroup calibration Intrinsics & Extrinsics
* @brief Intrinsic and extrinsic properties.
*/
/**
* @ingroup calibration
* Stream intrinsics,
2018-04-03 18:27:17 +03:00
*/
struct MYNTEYE_API Intrinsics {
2018-05-16 05:31:31 +03:00
/** The width of the image in pixels */
2018-04-03 17:10:25 +03:00
std::uint16_t width;
2018-05-16 05:31:31 +03:00
/** The height of the image in pixels */
2018-04-03 17:10:25 +03:00
std::uint16_t height;
2018-05-16 05:31:31 +03:00
/** The focal length of the image plane, as a multiple of pixel width */
2018-04-03 17:10:25 +03:00
double fx;
2018-05-16 05:31:31 +03:00
/** The focal length of the image plane, as a multiple of pixel height */
2018-04-03 17:10:25 +03:00
double fy;
2018-05-16 05:31:31 +03:00
/** The horizontal coordinate of the principal point of the image */
2018-04-03 17:10:25 +03:00
double cx;
2018-05-16 05:31:31 +03:00
/** The vertical coordinate of the principal point of the image */
2018-04-03 17:10:25 +03:00
double cy;
2018-05-16 05:31:31 +03:00
/** The distortion model of the image */
2018-04-03 17:10:25 +03:00
std::uint8_t model;
2018-05-16 05:31:31 +03:00
/** The distortion coefficients: k1,k2,p1,p2,k3 */
2018-04-03 17:10:25 +03:00
double coeffs[5];
};
2018-04-23 18:11:11 +03:00
MYNTEYE_API
std::ostream &operator<<(std::ostream &os, const Intrinsics &in);
2018-04-19 12:23:02 +03:00
2018-04-03 18:27:17 +03:00
/**
* @ingroup calibration
* IMU intrinsics: scale, drift and variances.
2018-04-03 18:27:17 +03:00
*/
struct MYNTEYE_API ImuIntrinsics {
2018-04-03 17:10:25 +03:00
/**
2018-05-16 05:31:31 +03:00
* Scale matrix.
* \code
* Scale X cross axis cross axis
* cross axis Scale Y cross axis
* cross axis cross axis Scale Z
* \endcode
2018-04-03 17:10:25 +03:00
*/
double scale[3][3];
/* Zero-drift: X, Y, Z */
double drift[3];
/** Noise density variances */
double noise[3];
/** Random walk variances */
double bias[3];
};
2018-04-23 18:11:11 +03:00
MYNTEYE_API
std::ostream &operator<<(std::ostream &os, const ImuIntrinsics &in);
2018-04-19 12:23:02 +03:00
2018-04-03 18:27:17 +03:00
/**
* @ingroup calibration
* Motion intrinsics, including accelerometer and gyroscope.
2018-04-03 18:27:17 +03:00
*/
struct MYNTEYE_API MotionIntrinsics {
2018-05-16 05:31:31 +03:00
ImuIntrinsics accel; /**< Accelerometer intrinsics */
ImuIntrinsics gyro; /**< Gyroscope intrinsics */
2018-04-03 17:10:25 +03:00
};
2018-04-23 18:11:11 +03:00
MYNTEYE_API
std::ostream &operator<<(std::ostream &os, const MotionIntrinsics &in);
2018-04-19 12:23:02 +03:00
2018-04-03 17:10:25 +03:00
/**
2018-04-03 18:27:17 +03:00
* @ingroup calibration
2018-04-06 04:12:09 +03:00
* Extrinsics, represent how the different datas are connected.
2018-04-03 17:10:25 +03:00
*/
2018-04-04 04:21:45 +03:00
struct MYNTEYE_API Extrinsics {
2018-05-16 05:31:31 +03:00
double rotation[3][3]; /**< Rotation matrix */
double translation[3]; /**< Translation vector */
2018-04-29 09:47:35 +03:00
2018-05-16 05:31:31 +03:00
/**
* Inverse this extrinsics.
* @return the inversed extrinsics.
*/
2018-04-29 09:47:35 +03:00
Extrinsics Inverse() const {
return {{{rotation[0][0], rotation[1][0], rotation[2][0]},
{rotation[0][1], rotation[1][1], rotation[2][1]},
{rotation[0][2], rotation[1][2], rotation[2][2]}},
{-translation[0], -translation[1], -translation[2]}};
}
2018-04-03 17:10:25 +03:00
};
2018-04-23 18:11:11 +03:00
MYNTEYE_API
2018-04-19 12:23:02 +03:00
std::ostream &operator<<(std::ostream &os, const Extrinsics &ex);
2018-04-03 18:27:17 +03:00
/**
* @defgroup datatypes Datatypes
* @brief Public data types.
*/
/**
* @ingroup datatypes
* Image data.
*/
2018-04-04 04:21:45 +03:00
struct MYNTEYE_API ImgData {
2018-04-03 17:10:25 +03:00
/** Image frame id */
std::uint16_t frame_id;
2018-10-23 11:08:59 +03:00
/** Image timestamp in 1us */
2018-08-01 17:00:38 +03:00
std::uint64_t timestamp;
2018-05-13 05:34:03 +03:00
/** Image exposure time, virtual value in [1, 480] */
2018-04-03 17:10:25 +03:00
std::uint16_t exposure_time;
2018-04-08 17:35:49 +03:00
void Reset() {
frame_id = 0;
timestamp = 0;
exposure_time = 0;
}
2018-04-08 20:20:00 +03:00
ImgData() {
Reset();
}
ImgData(const ImgData &other) {
frame_id = other.frame_id;
timestamp = other.timestamp;
exposure_time = other.exposure_time;
}
ImgData &operator=(const ImgData &other) {
frame_id = other.frame_id;
timestamp = other.timestamp;
exposure_time = other.exposure_time;
return *this;
}
2018-04-03 17:10:25 +03:00
};
2018-04-03 18:27:17 +03:00
/**
* @ingroup datatypes
* IMU data.
*/
2018-04-04 04:21:45 +03:00
struct MYNTEYE_API ImuData {
2018-12-21 16:04:40 +02:00
/** Imu frame id */
std::uint32_t frame_id;
2018-07-21 10:34:07 +03:00
/** accel or gyro flag:1 for accel,2 for gyro,3 for both */
std::uint8_t flag;
2018-08-03 14:31:36 +03:00
/** IMU timestamp in 1us */
2018-07-21 10:34:07 +03:00
std::uint64_t timestamp;
2018-04-03 17:10:25 +03:00
/** IMU accelerometer data for 3-axis: X, Y, Z. */
double accel[3];
/** IMU gyroscope data for 3-axis: X, Y, Z. */
double gyro[3];
/** IMU temperature */
double temperature;
2018-04-08 17:35:49 +03:00
void Reset() {
2018-07-21 10:34:07 +03:00
flag = 0;
2018-04-08 17:35:49 +03:00
timestamp = 0;
std::fill(accel, accel + 3, 0);
std::fill(gyro, gyro + 3, 0);
temperature = 0;
}
2018-04-08 20:20:00 +03:00
ImuData() {
Reset();
}
2018-04-03 17:10:25 +03:00
};
2018-04-09 19:26:22 +03:00
/**
* @ingroup datatypes
* Option info.
*/
struct MYNTEYE_API OptionInfo {
2018-05-16 05:31:31 +03:00
/** Minimum value */
2018-04-09 19:26:22 +03:00
std::int32_t min;
2018-05-16 05:31:31 +03:00
/** Maximum value */
2018-04-09 19:26:22 +03:00
std::int32_t max;
2018-05-16 05:31:31 +03:00
/** Default value */
2018-04-09 19:26:22 +03:00
std::int32_t def;
};
MYNTEYE_API
std::ostream &operator<<(std::ostream &os, const OptionInfo &info);
2018-04-03 05:27:28 +03:00
MYNTEYE_END_NAMESPACE
2018-10-27 16:24:04 +03:00
#endif // MYNTEYE_TYPES_H_