6#ifndef OPENEV_DATASETS_ABSTRACT_DATASET_HPP
7#define OPENEV_DATASETS_ABSTRACT_DATASET_HPP
16#include <opencv2/core/types.hpp>
21[[maybe_unused]]
constexpr bool USING_ABSTRACT_DATASET_HPP =
true;
32class AbstractDataset {
37 using Progress = std::function<void(
double,
double)>;
39 AbstractDataset() =
default;
40 virtual ~AbstractDataset() =
default;
41 AbstractDataset(
const AbstractDataset &) =
delete;
42 AbstractDataset(AbstractDataset &&) noexcept = default;
43 AbstractDataset &operator=(const AbstractDataset &) = delete;
44 AbstractDataset &operator=(AbstractDataset &&) noexcept = default;
50 [[nodiscard]] virtual std::
string name() const = 0;
56 [[nodiscard]] virtual std::
string shortname() const = 0;
62 [[nodiscard]] virtual std::vector<std::
string>
sequences() const = 0;
69 [[nodiscard]] virtual std::
string url(const std::
string &
sequence) const = 0;
101 [[nodiscard]] std::
string directory() const;
108 [[nodiscard]] std::
string path(const std::
string &
sequence) const;
142 [[nodiscard]] inline
bool isOpen()
const {
143 return reader_ !=
nullptr;
150 [[nodiscard]]
inline const std::string &
sequence()
const {
160 return reader_->events(n);
168 reader_->prefetch(n);
176 return reader_->prefetchCapacity();
184 inline void setRoi(
const cv::Rect &roi) {
185 reader_->setRoi(roi);
192 [[nodiscard]]
inline cv::Rect
getRoi()
const {
193 const cv::Rect roi = reader_->getRoi();
194 return roi.empty() ? cv::Rect(cv::Point(0, 0),
sensorSize(sequence_)) : roi;
208 [[nodiscard]]
inline const FrameFileVector &
frames()
const {
216 [[nodiscard]]
inline const ImuVector &
imu()
const {
224 [[nodiscard]]
inline const std::string &
error()
const {
230 [[nodiscard]]
virtual bool isComplete_(
const std::string &
path)
const = 0;
231 virtual void load_(
const std::string &
sequence) = 0;
232 void assign_(std::unique_ptr<AbstractReader_> reader, FrameFileVector
frames, ImuVector
imu);
237 std::string directory_;
238 std::string sequence_;
239 std::unique_ptr<AbstractReader_> reader_;
240 FrameFileVector frames_;
Abstract base class for event readers.
std::function< void(double, double)> Progress
Function called while a sequence is being downloaded.
Definition abstract-dataset.hpp:37
const std::string & error() const
Reason why the last download() failed.
Definition abstract-dataset.hpp:224
virtual std::string cameraName(const std::string &sequence) const =0
Name of the camera that recorded a sequence.
virtual cv::Size sensorSize(const std::string &sequence) const =0
Sensor size of the camera that recorded a sequence.
virtual std::vector< std::string > sequences() const =0
Sequences published by the dataset.
const FrameFileVector & frames() const
Frames of the sequence, empty if it has none.
Definition abstract-dataset.hpp:208
void prefetch(const std::size_t n)
Keep the queue at a given number of events from a background thread, see AbstractReader_::prefetch().
Definition abstract-dataset.hpp:167
bool download(const std::string &sequence, const Progress &progress=nullptr)
Download a sequence and extract it in path(). Nothing is done if the sequence is already available.
Definition abstract-dataset.cpp:165
cv::Rect getRoi() const
Get the region of interest.
Definition abstract-dataset.hpp:192
bool open(const std::string &sequence, const Progress &progress=nullptr)
Open a sequence, downloading it first if it is not available.
Definition abstract-dataset.cpp:196
static std::string cacheDirectory()
Directory where downloaded datasets are kept by default.
Definition abstract-dataset.cpp:140
std::string directory() const
Directory where the sequences of this dataset are kept.
Definition abstract-dataset.cpp:153
virtual std::string name() const =0
Name of the dataset.
virtual std::string url(const std::string &sequence) const =0
Address of the zip file of a sequence.
bool isOpen() const
Check if a sequence is open.
Definition abstract-dataset.hpp:142
void setDirectory(const std::string &directory)
Set the directory where the sequences of this dataset are kept.
Definition abstract-dataset.cpp:149
std::string path(const std::string &sequence) const
Directory of a sequence.
Definition abstract-dataset.cpp:157
std::size_t prefetchCapacity() const
Number of events prefetch() keeps in the queue, see AbstractReader_::prefetchCapacity().
Definition abstract-dataset.hpp:175
const ImuVector & imu() const
Inertial measurements of the sequence, empty if it has none.
Definition abstract-dataset.hpp:216
bool isAvailable(const std::string &sequence) const
Check if a sequence has been downloaded.
Definition abstract-dataset.cpp:161
void close()
Close the sequence.
Definition abstract-dataset.cpp:209
void reset()
Go back to the beginning of the sequence, see AbstractReader_::reset().
Definition abstract-dataset.hpp:200
void setRoi(const cv::Rect &roi)
Deliver only the events inside a region of interest, as the cameras of the devices module do....
Definition abstract-dataset.hpp:184
const std::string & sequence() const
Name of the sequence that is open.
Definition abstract-dataset.hpp:150
virtual std::string shortname() const =0
Short name of the dataset, also used as directory name.
ConcurrentQueue & events(const std::size_t n=0)
Read a given number of events, add them to the queue, and return it, see AbstractReader_::events().
Definition abstract-dataset.hpp:159
Queue container for basic event structures, safe between a thread that pushes and a thread that pops.
ConcurrentQueuei ConcurrentQueue
Definition concurrent_queue.hpp:93
Size2 Size
Definition types.hpp:325