OpenEV
Extending OpenCV to event-based vision
Loading...
Searching...
No Matches
abstract-reader.hpp
Go to the documentation of this file.
1
6#ifndef OPENEV_READERS_ABSTRACT_READER_HPP
7#define OPENEV_READERS_ABSTRACT_READER_HPP
8
10#include "openev/core/types.hpp"
11#include <array>
12#include <atomic>
13#include <cstddef>
14#include <memory>
15#include <opencv2/core/types.hpp>
16#include <thread>
17
18namespace ev {
19[[maybe_unused]] constexpr bool USING_ABSTRACT_READER_HPP = true;
20
29public:
31 AbstractReader_() = default;
32 virtual ~AbstractReader_();
33 AbstractReader_(const AbstractReader_ &) = delete;
34 AbstractReader_(AbstractReader_ &&) noexcept = delete;
35 AbstractReader_ &operator=(const AbstractReader_ &) = delete;
36 AbstractReader_ &operator=(AbstractReader_ &&) noexcept = delete;
38
46 [[nodiscard]] inline ConcurrentQueue &events(const std::size_t n = 0) {
47 if(n == 0 && queue_) {
48 return *queue_;
49 }
50 return fill_(n);
51 }
52
57 void prefetch(const std::size_t n);
58
63 [[nodiscard]] inline std::size_t prefetchCapacity() const {
64 return level_;
65 }
66
70 void reset();
71
78 void setTimeTransform(const TimeType offset, const TimeType scale = 1);
79
85 void setRoi(const cv::Rect &roi);
86
91 [[nodiscard]] inline cv::Rect getRoi() const {
92 return roi_;
93 }
94
95protected:
97 virtual std::size_t read_(Event *events, const std::size_t max) = 0;
98 virtual void reset_() = 0;
99 bool stop_();
101
102private:
103 std::unique_ptr<ConcurrentQueue> queue_;
104 std::thread thread_;
105 std::atomic<bool> running_{false};
106 std::atomic<bool> finished_{false};
107 std::size_t level_{0};
108 TimeType timeOffset_{0};
109 TimeType timeScale_{1};
110 cv::Rect roi_;
111
112 static constexpr std::size_t BLOCK = 512;
113 std::array<Event, BLOCK> block_;
114 std::size_t blockPos_{0};
115 std::size_t blockCount_{0};
116
117 ConcurrentQueue &fill_(const std::size_t n);
118 void readBlock_(const std::size_t max);
119 void resize_(const std::size_t capacity);
120 void start_();
121};
122
123} // namespace ev
124
125#endif // OPENEV_READERS_ABSTRACT_READER_HPP
This is an auxiliary class. This class cannot be instanced.
Definition abstract-reader.hpp:28
void reset()
Go back to the beginning, discarding the events in the queue.
Definition abstract-reader.cpp:59
void setRoi(const cv::Rect &roi)
Deliver only the events inside a region of interest. The events keep their coordinates.
Definition abstract-reader.cpp:82
ConcurrentQueue & events(const std::size_t n=0)
Read a given number of events, add them to the queue, and return it.
Definition abstract-reader.hpp:46
cv::Rect getRoi() const
Get the region of interest.
Definition abstract-reader.hpp:91
void setTimeTransform(const TimeType offset, const TimeType scale=1)
Transform the timestamp of every event read from now on as (t - offset) * scale.
Definition abstract-reader.cpp:73
void prefetch(const std::size_t n)
Keep the queue at a given number of events from a background thread.
Definition abstract-reader.cpp:48
std::size_t prefetchCapacity() const
Number of events prefetch() keeps in the queue.
Definition abstract-reader.hpp:63
Queue container for basic event structures, safe between a thread that pushes and a thread that pops.
ConcurrentQueuei ConcurrentQueue
Definition concurrent_queue.hpp:93
Basic event-based vision structures based on OpenCV components.
Eventi Event
Definition types.hpp:262