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
10#include "openev/containers/vector.hpp"
11#include <atomic>
12#include <math.h>
13#include <opencv2/core/mat.hpp>
14#include <opencv2/core/mat.inl.hpp>
15#include <opencv2/core/types.hpp>
16#include <ostream>
17#include <queue>
18#include <stdint.h>
19#include <vector>
20
21typedef struct caer_device_handle {
22 uint16_t deviceType;
23} *caerDeviceHandle;
24
25namespace ev {
26
27namespace unit {
28template <typename T>
29constexpr double us(const T x) { return static_cast<double>(x) * 1e-6; }
30} // namespace unit
31
32constexpr double EARTH_GRAVITY = 9.80665;
33constexpr double DEG2RAD = M_PI / 180.0;
34constexpr double SCALE_16B_8B = 1.0 / 256.0;
35
36struct BiasValue {
37 uint8_t coarse;
38 uint8_t fine;
39 [[nodiscard]] friend std::ostream &operator<<(std::ostream &os, const struct BiasValue &value) {
40 os << "Coarse: " << static_cast<int>(value.coarse) << ", Fine: " << static_cast<int>(value.fine);
41 return os;
42 }
43} __attribute__((aligned(2)));
44
54class StampedMat : public cv::Mat {
55public:
56 double t;
57};
58using StampedMatVector = std::vector<StampedMat>;
59using StampedMatQueue = std::queue<StampedMat>;
60
64struct xyz_t {
65 double x{0};
66 double y{0};
67 double z{0};
68
69 [[nodiscard]] bool empty() const {
70 return x == 0 && y == 0 && z == 0;
71 }
72
73 void release() {
74 x = y = z = 0;
75 }
76
77 friend std::ostream &operator<<(std::ostream &os, const xyz_t &xyz) {
78 os << "(" << xyz.x << ", " << xyz.y << ", " << xyz.z << ")";
79 return os;
80 }
81} __attribute__((aligned(32)));
82
92struct Imu {
93 double t{0};
94 xyz_t linear_acceleration;
95 xyz_t angular_velocity;
96
97 [[nodiscard]] bool empty() const {
98 return t == 0 && linear_acceleration.empty() && angular_velocity.empty();
99 }
100
101 void release() {
102 t = 0;
103 linear_acceleration.release();
104 angular_velocity.release();
105 }
106
107 friend std::ostream &operator<<(std::ostream &os, const Imu &imu) {
108 os << "t: " << imu.t << ", acc: " << imu.linear_acceleration << ", gyr: " << imu.angular_velocity;
109 return os;
110 }
111} __attribute__((aligned(128)));
112using ImuVector = std::vector<Imu>;
113using ImuQueue = std::queue<Imu>;
114
119public:
121 AbstractCamera() = default;
123 AbstractCamera(const AbstractCamera &) = delete;
124 AbstractCamera(AbstractCamera &&) noexcept = delete;
125 AbstractCamera &operator=(const AbstractCamera &) = delete;
126 AbstractCamera &operator=(AbstractCamera &&) noexcept = delete;
128
133 inline void setTimeOffset(const double offset) {
134 timeOffset_ = offset;
135 }
136
140 void start();
141
145 void stop();
146
151 [[nodiscard]] cv::Size getSensorSize() const;
152
157 [[nodiscard]] cv::Rect_<uint16_t> getRoi() const;
158
164 bool setRoi(const cv::Rect_<uint16_t> &roi);
165
172 BiasValue getBias(const int8_t config_bias, const uint8_t name) const;
173
181 bool setBias(const int8_t config_bias, const uint8_t name, const BiasValue &value);
182
187 void flush(const double msec) const;
188
194 virtual bool getData(Vector &events) = 0;
195
201 virtual bool getData(Queue &events) = 0;
202
203protected:
205 std::atomic<bool> running_{false};
206 caerDeviceHandle deviceHandler_{nullptr};
207 double timeOffset_{0};
208 cv::Rect_<uint16_t> roi_;
210
211 virtual void init() = 0;
212};
213
214} // namespace ev
215
216#endif // OPENEV_DEVICES_ABSTRACT_CAMERA_HPP
This is an auxiliary class. This class cannot be instanced.
Definition abstract-camera.hpp:118
cv::Size getSensorSize() const
Get device sensor size.
Definition abstract-camera.cpp:25
void flush(const double msec) const
Discard data during an interval of time.
Definition abstract-camera.cpp:66
virtual bool getData(Queue &events)=0
Get data.
bool setRoi(const cv::Rect_< uint16_t > &roi)
Set current ROI. Events outside the ROI are not considered. Images are cropped according to the ROI.
Definition abstract-camera.cpp:38
void start()
Start reading data.
Definition abstract-camera.cpp:16
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:57
cv::Rect_< uint16_t > getRoi() const
Get current ROI.
Definition abstract-camera.cpp:30
void setTimeOffset(const double offset)
Set offset to add after receiving events.
Definition abstract-camera.hpp:133
virtual bool getData(Vector &events)=0
Get data.
void stop()
Stop reading data.
Definition abstract-camera.cpp:21
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:51
This class extends cv::Mat to include timestamp.
Definition abstract-camera.hpp:54
Queue container for basic event structures.
Queuei Queue
Definition queue.hpp:153
Definition abstract-camera.hpp:21
Definition abstract-camera.hpp:36
This struct is used to store IMU data from a DAVIS event camera.
Definition abstract-camera.hpp:92
This struct is used to store linear acceleration and angular velocity.
Definition abstract-camera.hpp:64