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
11#include "openev/core/types.hpp"
12#include <atomic>
13#include <cstddef>
14#include <math.h>
15#include <opencv2/core/mat.hpp>
16#include <opencv2/core/mat.inl.hpp>
17#include <opencv2/core/types.hpp>
18#include <ostream>
19#include <queue>
20#include <stdint.h>
21#include <string>
22#include <vector>
23
24typedef struct caer_device_handle {
25 uint16_t deviceType;
26} *caerDeviceHandle;
27
28namespace ev {
29
30namespace unit {
31template <typename T>
32constexpr double us(const T x) { return static_cast<double>(x) * 1e-6; }
33} // namespace unit
34
35constexpr double EARTH_GRAVITY = 9.80665;
36constexpr double DEG2RAD = M_PI / 180.0;
37constexpr double SCALE_16B_8B = 1.0 / 256.0;
38
48class StampedMat : public cv::Mat {
49public:
50 TimeType t{0};
51
52 using cv::Mat::copyTo;
53
58 void copyTo(StampedMat &dst) const {
59 cv::Mat::copyTo(dst);
60 dst.t = t;
61 }
62
66 void release() {
67 cv::Mat::release();
68 t = 0;
69 }
70};
71using StampedMatVector = std::vector<StampedMat>;
72using StampedMatQueue = std::queue<StampedMat>;
73
77struct xyz_t {
78 double x{0};
79 double y{0};
80 double z{0};
81
82 [[nodiscard]] bool empty() const {
83 return x == 0 && y == 0 && z == 0;
84 }
85
86 void release() {
87 x = y = z = 0;
88 }
89
90 friend std::ostream &operator<<(std::ostream &os, const xyz_t &xyz) {
91 os << "(" << xyz.x << ", " << xyz.y << ", " << xyz.z << ")";
92 return os;
93 }
94};
95
105struct Imu {
106 TimeType t{0};
107 xyz_t linear_acceleration;
108 xyz_t angular_velocity;
109
110 [[nodiscard]] bool empty() const {
111 return t == 0 && linear_acceleration.empty() && angular_velocity.empty();
112 }
113
114 void release() {
115 t = 0;
116 linear_acceleration.release();
117 angular_velocity.release();
118 }
119
120 friend std::ostream &operator<<(std::ostream &os, const Imu &imu) {
121 os << "t: " << imu.t << ", acc: " << imu.linear_acceleration << ", gyr: " << imu.angular_velocity;
122 return os;
123 }
124};
125using ImuVector = std::vector<Imu>;
126using ImuQueue = std::queue<Imu>;
127
132public:
134 AbstractCamera() = default;
135 virtual ~AbstractCamera();
136 AbstractCamera(const AbstractCamera &) = delete;
137 AbstractCamera(AbstractCamera &&) noexcept = delete;
138 AbstractCamera &operator=(const AbstractCamera &) = delete;
139 AbstractCamera &operator=(AbstractCamera &&) noexcept = delete;
141
145 virtual void start() = 0;
146
150 void stop();
151
156 [[nodiscard]] bool isOpen() const {
157 return deviceHandler_ != nullptr;
158 }
159
164 [[nodiscard]] virtual bool hasAps() const = 0;
165
170 [[nodiscard]] virtual bool hasImu() const = 0;
171
176 [[nodiscard]] virtual cv::Size getSensorSize() const = 0;
177
182 [[nodiscard]] virtual std::string getSerialNumber() const = 0;
183
188 [[nodiscard]] uint64_t getResetTime() const {
189 return resetTime_;
190 }
191
196 [[nodiscard]] cv::Rect_<uint16_t> getRoi() const;
197
203 virtual bool setRoi(const cv::Rect_<uint16_t> &roi) = 0;
204
222 void setDefectivePixels(const std::string &defective_pixels_file);
223
228 void setContainerInterval(const uint32_t usec);
229
236 void setContainerSize(const uint32_t n);
237
243 bool getData(Vector &events);
244
250 bool getData(Queue &events);
251
257 bool getData(StampedMat &frame);
258
264 bool getData(StampedMatVector &frames);
265
271 bool getData(StampedMatQueue &frames);
272
278 bool getData(Imu &imu);
279
285 bool getData(ImuVector &imu);
286
292 bool getData(ImuQueue &imu);
293
300 bool getData(Vector &events, StampedMat &frame);
301
308 bool getData(Vector &events, StampedMatVector &frames);
309
316 bool getData(Queue &events, StampedMatQueue &frames);
317
324 bool getData(Vector &events, Imu &imu);
325
332 bool getData(Vector &events, ImuVector &imu);
333
340 bool getData(Queue &events, ImuQueue &imu);
341
349 bool getData(Vector &events, StampedMat &frame, Imu &imu);
350
358 bool getData(Vector &events, StampedMatVector &frame, ImuVector &imu);
359
367 bool getData(Queue &events, StampedMatQueue &frame, ImuQueue &imu);
368
379 std::size_t getEventRaw(std::vector<uint64_t> &data);
380
394 std::size_t getEventRaw(uint64_t *&data, const bool allow_realloc = true);
395
400 void flush(const double usec) const;
401
402protected:
404 template <typename T1, typename T2, typename T3>
405 bool getData_([[maybe_unused]] T1 *dvs, [[maybe_unused]] T2 *aps, [[maybe_unused]] T3 *imu);
406
407 template <typename T>
408 std::size_t getEventRaw_(T &data, [[maybe_unused]] const bool allow_realloc);
409
410 void interpolate_(cv::Mat &frame) const;
411
418 virtual std::size_t setDvsFilterPixels([[maybe_unused]] const std::vector<cv::Point> &pixels) {
419 return 0;
420 }
421
422 std::atomic<bool> running_{false};
423 bool hasDefectivePixels_{false};
424 cv::Mat hotPixels_;
425 std::vector<cv::Point> saturatedPixels_;
426 caerDeviceHandle deviceHandler_{nullptr};
427 uint64_t resetTime_{0};
428 cv::Rect_<uint16_t> roi_;
429 bool filterRoiInSoftware_{false};
431};
432
433} // namespace ev
434
435#endif // OPENEV_DEVICES_ABSTRACT_CAMERA_HPP
This is an auxiliary class. This class cannot be instanced.
Definition abstract-camera.hpp:131
virtual cv::Size getSensorSize() const =0
Get device sensor size.
virtual bool setRoi(const cv::Rect_< uint16_t > &roi)=0
Set current ROI. Events outside the ROI are not considered. Images are cropped according to the ROI.
void setDefectivePixels(const std::string &defective_pixels_file)
Load a defective pixel file. Events on hot pixels are discarded, and saturated pixels are replaced by...
Definition abstract-camera.cpp:45
virtual bool hasImu() const =0
Check whether the device produces IMU data.
virtual void start()=0
Start reading data.
std::size_t getEventRaw(std::vector< uint64_t > &data)
Retrieve raw event data.
Definition abstract-camera.cpp:173
bool isOpen() const
Check whether the device was found and opened.
Definition abstract-camera.hpp:156
cv::Rect_< uint16_t > getRoi() const
Get current ROI.
Definition abstract-camera.cpp:37
virtual std::string getSerialNumber() const =0
Get device serial number, prefixed with the camera family.
void setContainerInterval(const uint32_t usec)
Set the maximum time interval between subsequent containers.
Definition abstract-camera.cpp:90
uint64_t getResetTime() const
Get device reset time.
Definition abstract-camera.hpp:188
void stop()
Stop reading data.
Definition abstract-camera.cpp:31
void setContainerSize(const uint32_t n)
Set the maximum number of events a container may hold before it is delivered. The limit applies to ea...
Definition abstract-camera.cpp:101
void flush(const double usec) const
Discard data during an interval of time.
Definition abstract-camera.cpp:177
virtual bool hasAps() const =0
Check whether the device produces APS frames.
bool getData(Vector &events)
Get DVS data.
Definition abstract-camera.cpp:139
This class extends cv::Mat to include timestamp.
Definition abstract-camera.hpp:48
void copyTo(StampedMat &dst) const
Copy image data and timestamp to another StampedMat.
Definition abstract-camera.hpp:58
void release()
Release the image data and reset the timestamp.
Definition abstract-camera.hpp:66
Queue container for basic event structures.
Queuei Queue
Definition queue.hpp:61
Definition abstract-camera.hpp:24
This struct is used to store IMU data from a DAVIS event camera.
Definition abstract-camera.hpp:105
This struct is used to store linear acceleration and angular velocity.
Definition abstract-camera.hpp:77
Basic event-based vision structures based on OpenCV components.
Vector container for basic event structures.
Vectori Vector
Definition vector.hpp:31