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
12#include "openev/core/imu.hpp"
13#include "openev/core/types.hpp"
14#include <atomic>
15#include <cstddef>
16#include <math.h>
17#include <opencv2/core/mat.hpp>
18#include <opencv2/core/mat.inl.hpp>
19#include <opencv2/core/types.hpp>
20#include <ostream>
21#include <queue>
22#include <stdint.h>
23#include <string>
24#include <vector>
25
26typedef struct caer_device_handle {
27 uint16_t deviceType;
28} *caerDeviceHandle;
29
30namespace ev {
31
32namespace unit {
33template <typename T>
34constexpr double us(const T x) { return static_cast<double>(x) * 1e-6; }
35} // namespace unit
36
37constexpr double EARTH_GRAVITY = 9.80665;
38constexpr double DEG2RAD = M_PI / 180.0;
39constexpr double SCALE_16B_8B = 1.0 / 256.0;
40
45public:
47 AbstractCamera() = default;
48 virtual ~AbstractCamera();
49 AbstractCamera(const AbstractCamera &) = delete;
50 AbstractCamera(AbstractCamera &&) noexcept = delete;
51 AbstractCamera &operator=(const AbstractCamera &) = delete;
52 AbstractCamera &operator=(AbstractCamera &&) noexcept = delete;
54
58 virtual void start() = 0;
59
63 void stop();
64
69 [[nodiscard]] bool isOpen() const {
70 return deviceHandler_ != nullptr;
71 }
72
77 [[nodiscard]] virtual bool hasAps() const = 0;
78
83 [[nodiscard]] virtual bool hasImu() const = 0;
84
89 [[nodiscard]] virtual cv::Size getSensorSize() const = 0;
90
95 [[nodiscard]] virtual std::string getSerialNumber() const = 0;
96
101 [[nodiscard]] uint64_t getResetTime() const {
102 return resetTime_;
103 }
104
109 [[nodiscard]] cv::Rect_<uint16_t> getRoi() const;
110
116 virtual bool setRoi(const cv::Rect_<uint16_t> &roi) = 0;
117
135 void setDefectivePixels(const std::string &defective_pixels_file);
136
141 void setContainerInterval(const uint32_t usec);
142
149 void setContainerSize(const uint32_t n);
150
156 bool getData(Vector &events);
157
163 bool getData(Queue &events);
164
170 bool getData(StampedMat &frame);
171
177 bool getData(StampedMatVector &frames);
178
184 bool getData(StampedMatQueue &frames);
185
191 bool getData(Imu &imu);
192
198 bool getData(ImuVector &imu);
199
205 bool getData(ImuQueue &imu);
206
213 bool getData(Vector &events, StampedMat &frame);
214
221 bool getData(Vector &events, StampedMatVector &frames);
222
229 bool getData(Queue &events, StampedMatQueue &frames);
230
237 bool getData(Vector &events, Imu &imu);
238
245 bool getData(Vector &events, ImuVector &imu);
246
253 bool getData(Queue &events, ImuQueue &imu);
254
262 bool getData(Vector &events, StampedMat &frame, Imu &imu);
263
271 bool getData(Vector &events, StampedMatVector &frame, ImuVector &imu);
272
280 bool getData(Queue &events, StampedMatQueue &frame, ImuQueue &imu);
281
292 std::size_t getEventRaw(std::vector<uint64_t> &data);
293
307 std::size_t getEventRaw(uint64_t *&data, const bool allow_realloc = true);
308
313 void flush(const double usec) const;
314
315protected:
317 template <typename T1, typename T2, typename T3>
318 bool getData_([[maybe_unused]] T1 *dvs, [[maybe_unused]] T2 *aps, [[maybe_unused]] T3 *imu);
319
320 template <typename T>
321 std::size_t getEventRaw_(T &data, [[maybe_unused]] const bool allow_realloc);
322
323 void interpolate_(cv::Mat &frame) const;
324
331 virtual std::size_t setDvsFilterPixels([[maybe_unused]] const std::vector<cv::Point> &pixels) {
332 return 0;
333 }
334
335 std::atomic<bool> running_{false};
336 bool hasDefectivePixels_{false};
337 cv::Mat hotPixels_;
338 std::vector<cv::Point> saturatedPixels_;
339 caerDeviceHandle deviceHandler_{nullptr};
340 uint64_t resetTime_{0};
341 cv::Rect_<uint16_t> roi_;
342 bool filterRoiInSoftware_{false};
344};
345
346} // namespace ev
347
348#endif // OPENEV_DEVICES_ABSTRACT_CAMERA_HPP
This is an auxiliary class. This class cannot be instanced.
Definition abstract-camera.hpp:44
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:69
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:101
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 frames.hpp:27
Timestamped images.
Inertial measurements.
Queue container for basic event structures.
Queuei Queue
Definition queue.hpp:40
Definition abstract-camera.hpp:26
This struct is used to store IMU data from a DAVIS event camera.
Definition imu.hpp:48
Basic event-based vision structures based on OpenCV components.
Vector container for basic event structures.
Vectori Vector
Definition vector.hpp:31