OpenEV
Extending OpenCV to event-based vision
Loading...
Searching...
No Matches
abstract-camera.hpp
Go to the documentation of this file.
1
6#ifndef OPENEV_DEVICES_ABSTRACT_CAMERA_HPP
7#define OPENEV_DEVICES_ABSTRACT_CAMERA_HPP
8
9#include "openev/containers/queue.hpp"
10#include "openev/containers/vector.hpp"
11#include <atomic>
12#include <math.h>
13#include <opencv2/core/mat.hpp>
14#include <opencv2/core/types.hpp>
15#include <ostream>
16#include <queue>
17#include <stdint.h>
18#include <vector>
19
20typedef struct caer_device_handle {
21 uint16_t deviceType;
23
24namespace ev {
25
26namespace unit {
27template <typename T>
28constexpr double us(const T x) { return static_cast<double>(x) * 1e-6; }
29} // namespace unit
30
31constexpr double EARTH_GRAVITY = 9.80665;
32constexpr double DEG2RAD = M_PI / 180.0;
33constexpr double SCALE_16B_8B = 1.0 / 256.0;
34
35struct BiasValue {
36 uint8_t coarse;
37 uint8_t fine;
38 [[nodiscard]] friend std::ostream &operator<<(std::ostream &os, const struct BiasValue &value) {
39 os << "Coarse: " << static_cast<int>(value.coarse) << ", Fine: " << static_cast<int>(value.fine);
40 return os;
41 }
42} __attribute__((aligned(2)));
43
53class StampedMat : public cv::Mat {
54public:
55 double t;
56};
57using StampedMatVector = std::vector<StampedMat>;
58using StampedMatQueue = std::queue<StampedMat>;
59
63struct xyz_t {
64 double x{0};
65 double y{0};
66 double z{0};
67
68 [[nodiscard]] bool empty() const {
69 return x == 0 && y == 0 && z == 0;
70 }
71
72 void release() {
73 x = y = z = 0;
74 }
75
76 friend std::ostream &operator<<(std::ostream &os, const xyz_t &xyz) {
77 os << "(" << xyz.x << ", " << xyz.y << ", " << xyz.z << ")";
78 return os;
79 }
80} __attribute__((aligned(32)));
81
91struct Imu {
92 double t{0};
93 xyz_t linear_acceleration;
94 xyz_t angular_velocity;
95
96 [[nodiscard]] bool empty() const {
97 return t == 0 && linear_acceleration.empty() && angular_velocity.empty();
98 }
99
100 void release() {
101 t = 0;
102 linear_acceleration.release();
103 angular_velocity.release();
104 }
105
106 friend std::ostream &operator<<(std::ostream &os, const Imu &imu) {
107 os << "t: " << imu.t << ", acc: " << imu.linear_acceleration << ", gyr: " << imu.angular_velocity;
108 return os;
109 }
110} __attribute__((aligned(128)));
111using ImuVector = std::vector<Imu>;
112using ImuQueue = std::queue<Imu>;
113
118public:
120 AbstractCamera_() = default;
121 virtual ~AbstractCamera_() = default;
122 AbstractCamera_(const AbstractCamera_ &) = delete;
123 AbstractCamera_(AbstractCamera_ &&) noexcept = delete;
124 AbstractCamera_ &operator=(const AbstractCamera_ &) = delete;
125 AbstractCamera_ &operator=(AbstractCamera_ &&) noexcept = delete;
132 inline void setTimeOffset(const double offset) {
133 timeOffset_ = offset;
134 }
135
139 virtual void start() = 0;
140
144 void stop();
145
150 [[nodiscard]] cv::Size getSensorSize() const;
151
156 [[nodiscard]] cv::Rect getRoi() const;
157
163 bool setRoi(const cv::Rect &roi);
164
171 BiasValue getBias(const int8_t config_bias, const uint8_t name) const;
172
180 bool setBias(const int8_t config_bias, const uint8_t name, const BiasValue &value);
181
186 void flush(double msec) const;
187
193 virtual bool getData(Vector &events) = 0;
194
200 virtual bool getData(Queue &events) = 0;
201
202protected:
204 std::atomic<bool> running_{false};
205 caerDeviceHandle deviceHandler_{nullptr};
206 double timeOffset_{0};
207 cv::Rect roi_;
209};
210
211} // namespace ev
212
213#endif // OPENEV_DEVICES_ABSTRACT_CAMERA_HPP
This is an auxiliary class. This class cannot be instanced.
Definition abstract-camera.hpp:117
cv::Rect getRoi() const
Get current ROI.
Definition abstract-camera.cpp:20
void setTimeOffset(const double offset)
Set offset to add after receiving events.
Definition abstract-camera.hpp:132
BiasValue getBias(const int8_t config_bias, const uint8_t name) const
Retrieve the bias value associated with a specific configuration and name.
Definition abstract-camera.cpp:41
virtual bool getData(Queue &events)=0
Get data.
void flush(double msec) const
Discard data during an interval of time.
Definition abstract-camera.cpp:56
bool setBias(const int8_t config_bias, const uint8_t name, const BiasValue &value)
Set the bias value associated with a specific configuration and name.
Definition abstract-camera.cpp:47
virtual bool getData(Vector &events)=0
Get data.
bool setRoi(const cv::Rect &roi)
Set current ROI. Events outside the ROI are not considered. Images are cropped according to the ROI.
Definition abstract-camera.cpp:28
void stop()
Stop reading data.
Definition abstract-camera.cpp:11
cv::Size getSensorSize() const
Get device sensor size.
Definition abstract-camera.cpp:15
virtual void start()=0
Start reading data.
This class extends std::queue to implement event queues. For more information, please refer here.
Definition queue.hpp:35
This class extends cv::Mat to include timestamp.
Definition abstract-camera.hpp:53
This class extends std::vector to implement event vectors. For more information, please refer here.
Definition vector.hpp:36
Definition abstract-camera.hpp:20
Definition abstract-camera.hpp:35
This struct is used to store IMU data from a DAVIS event camera.
Definition abstract-camera.hpp:91
This struct is used to store linear acceleration and angular velocity.
Definition abstract-camera.hpp:63