6#ifndef OPENEV_DEVICES_ABSTRACT_CAMERA_HPP
7#define OPENEV_DEVICES_ABSTRACT_CAMERA_HPP
15#include <opencv2/core/mat.hpp>
16#include <opencv2/core/mat.inl.hpp>
17#include <opencv2/core/types.hpp>
32constexpr double us(
const T x) {
return static_cast<double>(x) * 1e-6; }
35constexpr double EARTH_GRAVITY = 9.80665;
36constexpr double DEG2RAD = M_PI / 180.0;
37constexpr double SCALE_16B_8B = 1.0 / 256.0;
52 using cv::Mat::copyTo;
71using StampedMatVector = std::vector<StampedMat>;
72using StampedMatQueue = std::queue<StampedMat>;
82 [[nodiscard]]
bool empty()
const {
83 return x == 0 && y == 0 && z == 0;
90 friend std::ostream &operator<<(std::ostream &os,
const xyz_t &xyz) {
91 os <<
"(" << xyz.x <<
", " << xyz.y <<
", " << xyz.z <<
")";
107 xyz_t linear_acceleration;
108 xyz_t angular_velocity;
110 [[nodiscard]]
bool empty()
const {
111 return t == 0 && linear_acceleration.empty() && angular_velocity.empty();
116 linear_acceleration.release();
117 angular_velocity.release();
120 friend std::ostream &operator<<(std::ostream &os,
const Imu &imu) {
121 os <<
"t: " << imu.t <<
", acc: " << imu.linear_acceleration <<
", gyr: " << imu.angular_velocity;
125using ImuVector = std::vector<Imu>;
126using ImuQueue = std::queue<Imu>;
157 return deviceHandler_ !=
nullptr;
164 [[nodiscard]]
virtual bool hasAps()
const = 0;
170 [[nodiscard]]
virtual bool hasImu()
const = 0;
196 [[nodiscard]] cv::Rect_<uint16_t>
getRoi()
const;
203 virtual bool setRoi(
const cv::Rect_<uint16_t> &roi) = 0;
264 bool getData(StampedMatVector &frames);
271 bool getData(StampedMatQueue &frames);
358 bool getData(
Vector &events, StampedMatVector &frame, ImuVector &imu);
367 bool getData(
Queue &events, StampedMatQueue &frame, ImuQueue &imu);
379 std::size_t
getEventRaw(std::vector<uint64_t> &data);
394 std::size_t
getEventRaw(uint64_t *&data,
const bool allow_realloc =
true);
400 void flush(
const double usec)
const;
404 template <
typename T1,
typename T2,
typename T3>
405 bool getData_([[maybe_unused]] T1 *dvs, [[maybe_unused]] T2 *aps, [[maybe_unused]] T3 *imu);
407 template <
typename T>
408 std::size_t getEventRaw_(T &data, [[maybe_unused]]
const bool allow_realloc);
410 void interpolate_(cv::Mat &frame)
const;
418 virtual std::size_t setDvsFilterPixels([[maybe_unused]]
const std::vector<cv::Point> &pixels) {
422 std::atomic<bool> running_{
false};
423 bool hasDefectivePixels_{
false};
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};
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