DvsenseDriver  1.2.4
The SDK for dvsense products.
Loading...
Searching...
No Matches
Use Dynamic Vision Camera

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

Operate The Camera

In DVSenseDriver, all cameras are managed through the dvsense::DvsCameraManager class.

Find Cameras

// Find all cameras
std::vector<dvsense::CameraDescription> cameraDescs = cameraManager.getCameraDescs();
Camera Manager class.
Definition DvsCameraManager.hpp:36
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.
std::shared_ptr< DvsCamera > CameraDevice
Shared pointer to manage camera devices.
Definition DvsCameraManager.hpp:29

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, data streaming does not start by default, so you need to start it manually.

Attention: Before starting data streaming, please either register the callback function described in Asynchronously Process Events or configure the rules described in Synchronously Process Events.

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

Acquire And Process Events

DVSenseDriver provides two methods for acquiring and processing camera data to meet different needs and scenarios.

  • Asynchronous method: Based on callback functions. It offers better real-time performance but is more difficult to develop.
  • Synchronous method: Simpler to develop and broadly applicable, but with weaker real-time performance.
    • Acquire a fixed number of events.
    • Acquire events within a fixed time period.

The synchronous and asynchronous processing methods can be used at the same time. However, only one of the two synchronous acquisition modes can be active at once. In other words, you can both register callback functions and actively obtain the next batch of data through dvsense::DvsCamera::getNextBatch, but getNextBatch can only be configured for either fixed-time or fixed-count acquisition.

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 is 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, keep callback execution time as short as possible. Otherwise, data may accumulate and cause the program to crash.

You can use dvsense::DvsCamera::addEventsStreamHandleCallback to add multiple callback functions. When the event stream is available, these callback functions are executed sequentially in registration order. You can also record the callback ID returned by dvsense::DvsCamera::addEventsStreamHandleCallback and remove callbacks that are no longer needed through dvsense::DvsCamera::removeEventsStreamHandleCallback.

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 either the number of events or the acquisition time window, and then obtain the corresponding event data through dvsense::DvsCamera::getNextBatch.

If you want to acquire a fixed number of events, set the required number through dvsense::DvsCamera::setBatchEventsNum.

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

If you want to acquire events within a fixed time period, set the required time interval through dvsense::DvsCamera::setBatchEventsTime.

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

Once the settings are completed, call dvsense::DvsCamera::getNextBatch 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 write the camera's raw data into a raw file. See raw file for subsequent playback and processing.

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

The Next Section