DvsenseDriver  1.0.3
The SDK for dvsense products.
Use Dynamic Vision Camera

This part introduces how to control the camera through the API interface. And it also presents two methods for real-time processing of camera data, namely synchronous and asynchronous methods.

Operate The Camera

In the DvsenseDriver, all cameras are uniformly managed by using the dvsense::DvsCameraManager class.

Find Cameras

// find all cameras
std::vector<dvsense::CameraDescription> cameraDescs = cameraManager.getCameraDescs();
Camera Manager class.
Definition: DvsCameraManager.hpp:35
std::vector< CameraDescription > getCameraDescs()
Get the Camera Descriptions vector.

dvsense.CameraDescription contains information such as the manufacturer, model, and serial number of the camera.

Open Cameras

The dvsense::DvsCameraManager::openCamera interface can be used to open a specific camera by its serial number.

// Open the first camera found
dvsense::CameraDevice camera = cameraManager.openCamera(cameraDescs[0].serial);
CameraDevice openCamera(Serial serial)
Open a camera with the given serial number.
DVSENSE_API std::shared_ptr< DvsCamera > CameraDevice
Shared pointer to manage camera devices.
Definition: DvsCameraManager.hpp:28

The dvsense::CameraDevice is an easy - to - use wrapper for dvsense::DvsCamera. It is defined as typedef std::shared_ptr<DvsCamera> CameraDevice.

Start And Stop The Data Streaming

After opening the camera, the camera does not start data streaming by default, and you need to manually start it.

Attention!! Before starting the data streaming, please refer to the following Acquire And Process Events register Asynchronously Process Events callback function, or set Synchronously Process Events rules

camera->start(); // Start data streaming
camera->stop(); // Stop data streaming

Acquire And Process Events

In the DvsenseDriver, two methods for acquiring and processing camera data are provided to meet different needs and scenarios.

  • Asynchronous method: Based on callback functions, it offers better real - time performance but has a higher development difficulty.
  • Synchronous method: It is simple to develop and has wide applicability, but its real - time performance is relatively weak.
    • Acquire a fixed number of events.
    • Acquire events within a fixed time period.

The synchronous and asynchronous processing methods can be carried out simultaneously. However, only one of the two settings for event acquisition in the synchronous method can be used at a time. That is to say, you can both register a callback function and actively obtain the next batch of data using the dvsense::DvsCamera::getNextBatch function. Nevertheless, the dvsense::DvsCamera::getNextBatch function can only be set to one of the two settings: acquiring events for a fixed time or a fixed number.

Asynchronously Process Events

The camera provides the dvsense::DvsCamera::addEventsStreamHandleCallback interface, which allows real - time access to the event stream. Whenever a small packet of events is successfully transmitted and decoded, the registered callback function will be invoked.

The following is a usage example. In this example, the positions where events occur in a blank image img are assigned colors for subsequent visualization.

camera->addEventsStreamHandleCallback([&img](const dvsense::Event2D* begin, const dvsense::Event2D* end) {
// Perform certain operations or simply copy the data.
for (auto it = begin; it != end; ++it) {
img.at<cv::Vec3b>(it->y, it->x) = (it->polarity) ? color_on : color_off;
}
});

Warning: When using the callback function interface, you must minimize the execution time of the callback function as much as possible. Otherwise, it will lead to data accumulation and cause the program to crash.

You can use the dvsense::DvsCamera::addEventsStreamHandleCallback function to add multiple callback functions. When the event stream is available, these callback functions will be executed sequentially in the order of registration. You can also record the ID number of the callback function, which is the return value of dvsense::DvsCamera::addEventsStreamHandleCallback, and then remove the callback functions that are no longer needed through the dvsense::DvsCamera::removeEventsStreamHandleCallback function.

auto cb_id = camera->addEventsStreamHandleCallback([](const dvsense::Event2D* begin, const dvsense::Event2D* end) {
// Perform certain operations or simply copy the data.
});
camera->removeEventsStreamHandleCallback(cb_id);

Synchronously Process Events

The camera provides the dvsense::DvsCamera::getNextBatch interface. You can set the number or time period for event acquisition, and then obtain the specified event data through the dvsense::DvsCamera::getNextBatch interface.

If you want to acquire a fixed number of events, you need to set the required number of events in advance via the dvsense::DvsCamera::setBatchEventsNum interface.

camera->setBatchEventsNum(1000); // Set to acquire 1000 events.

In addition, if you want to acquire events within a fixed time period, you can set the required time interval through the dvsense::DvsCamera::setBatchEventsTime interface.

camera->setBatchEventsTime(1000); // Example: Set an event interval of 1000 microseconds.

Once the settings are completed, you need to call the dvsense::DvsCamera::getNextBatch interface to obtain the data.

dvsense::Event2DVector events;
bool ret = camera->getNextBatch(events);
for (auto event : events) {
// Do something with the events
}

Save The Data Of The Dynamic Vision Sensor

After the camera starts streaming data, you can use dvsense::DvsCamera::startRecording and dvsense::DvsCamera::stopRecording to stream the camera's raw data into a raw file. raw file,This is for subsequent playback and processing.

camera->startRecording(out_file_path); // Start recording
camera->stopRecording(); // Stop recording

The Next Section