OpenEV
Extending OpenCV to event-based vision
Loading...
Searching...
No Matches
example-event-camera-dataset.cpp

This is an example of how to use the EventCameraDataset class.

#include <chrono>
#include <cstddef>
#include <cstdlib>
#include <iostream>
#include <opencv2/core/types.hpp>
#include <thread>
int main(int /*argc*/, const char * /*argv*/[]) {
constexpr std::size_t EVENTS_TO_READ = 200000;
constexpr std::size_t BATCH = 10000;
constexpr int STEPS = 4;
std::cout << dataset.name() << " (" << dataset.shortname() << "), " << dataset.sequences().size() << " sequences" << '\n';
std::cout << "Camera " << dataset.cameraName("slider_close") << ", sensor " << dataset.sensorSize("slider_close") << '\n';
std::cout << "Kept in " << dataset.path("slider_close") << '\n';
std::cout << "Downloaded from " << dataset.url("slider_close") << (dataset.isAvailable("slider_close") ? " (already available)" : "") << '\n';
if(!dataset.open("slider_close")) {
std::cerr << dataset.error() << '\n';
return EXIT_FAILURE;
}
std::cout << "Open " << dataset.sequence() << ": " << dataset.frames().size() << " frames, " << dataset.imu().size() << " inertial measurements" << '\n';
std::cout << "Region of interest " << dataset.getRoi() << ", prefetch " << dataset.prefetchCapacity() << '\n';
dataset.setRoi(cv::Rect(60, 40, 120, 100));
dataset.prefetch(2 * BATCH);
std::cout << "Region of interest " << dataset.getRoi() << ", prefetch " << dataset.prefetchCapacity() << '\n';
std::size_t total = 0;
bool inside = true;
while(total < EVENTS_TO_READ && !dataset.events(BATCH).empty()) {
ev::ConcurrentQueue &events = dataset.events();
while(!events.empty()) {
inside = inside && dataset.getRoi().contains(events.front());
events.pop();
total++;
}
}
std::cout << "Read " << total << " events, " << (inside ? "all" : "not all") << " inside the region of interest" << '\n';
if(!dataset.open("slider_depth")) {
std::cerr << dataset.error() << '\n';
return EXIT_FAILURE;
}
std::cout << "Open " << dataset.sequence() << ": region of interest " << dataset.getRoi() << ", prefetch " << dataset.prefetchCapacity() << '\n';
ev::Player_ player(dataset);
player.setSpeed(2.0);
ev::Queue events;
ev::StampedMatQueue frames;
for(int i = 0; i < STEPS; i++) {
player.next(events, frames);
std::cout << "Playhead at " << player.playhead() / 1e3 << " ms: " << events.size() << " events and " << frames.size() << " frames so far" << '\n';
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
return EXIT_SUCCESS;
}
const std::string & error() const
Reason why the last download() failed.
Definition abstract-dataset.hpp:224
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
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
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 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
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
bool empty() const
Check if the queue holds no events.
Definition concurrent_queue.hpp:57
This class extends AbstractDataset to download and open the sequences of the Event-Camera Dataset.
Definition event-camera-dataset.hpp:24
std::string name() const override
Name of the dataset.
Definition event-camera-dataset.cpp:15
std::vector< std::string > sequences() const override
Sequences published by the dataset.
Definition event-camera-dataset.cpp:23
std::string url(const std::string &sequence) const override
Address of the zip file of a sequence.
Definition event-camera-dataset.cpp:27
std::string cameraName(const std::string &sequence) const override
Name of the camera that recorded a sequence.
Definition event-camera-dataset.cpp:35
std::string shortname() const override
Short name of the dataset, also used as directory name.
Definition event-camera-dataset.cpp:19
cv::Size sensorSize(const std::string &sequence) const override
Sensor size of the camera that recorded a sequence.
Definition event-camera-dataset.cpp:31
This class plays a reader, or anything offering events() and reset() as readers do.
Definition player.hpp:42
void setSpeed(const double speed)
Set the playback speed.
Definition player.hpp:54
void next(Queue &events)
Deliver what happened since the previous call.
Definition player.hpp:131
TimeType playhead() const
Current position of the playback, which starts at the timestamp of the first event.
Definition player.hpp:115
Queue container for basic event structures, safe between a thread that pushes and a thread that pops.
ConcurrentQueuei ConcurrentQueue
Definition concurrent_queue.hpp:93
The Event-Camera Dataset.
Timestamped images.
Real-time playback of a reader.
Queue container for basic event structures.
Queuei Queue
Definition queue.hpp:40