Raw Data Saving

This sample shows how to save live DELTA camera data as .dvs raw data. Use this sample when you want to record a live stream for later playback, offline processing, or repeatable testing.

Back to Code Samples.

Example Overview

Step SDK API Purpose
1 scanDevices() / openDevice() Find and open a connected DELTA Series camera.
2 applySensorSetting() Apply the recommended sensor setting file.
3 startStream() Start live USB streaming before saving raw data.
4 startRawSaving() / stopRawSaving() Save raw data continuously until the user stops it.
5 saveRawByTime() Save raw data for a fixed duration.
6 saveRawBySize() Save raw data until the target byte size is reached.
7 saveRawByEventCount() Save raw data until the target event count is reached.
8 saveRawByFrameCount() Save raw data until the target frame count is reached.
9 stopStream() / closeDevice() Stop streaming and release the device.

Expected Result

When raw data is saved successfully, a .dvs file is created with a timestamp and device suffix in the file name.

Raw data sample image

The timestamp fields are ordered as:

year-month-day-hour-minute-second

Code Walkthrough

Edit the User Control Panel

The USER CONTROL PANEL section is the only part you normally need to edit. Each option group has one active line and one or more commented alternatives. To use a different mode, comment out the current active line and uncomment the mode you want to use.

Select a Camera

const std::int32_t selectDeviceIndex = 0;

selectDeviceIndex = 0 selects the first detected camera from the latest scanDevices() result.

Select a Raw Saving Mode

Only one selected_savemode line should be active at a time.

(a) Continuous This is the default mode used by the example.

const std::string selected_savemode = "Continuous";

When this mode is active, press s to start raw saving and press q to stop saving and quit. Internally, the example calls startRawSaving() and stopRawSaving().

(b) Time To save for a fixed duration, uncomment the Time line and comment out the currently active Continuous line.

// const std::string selected_savemode = "Time";
const std::int32_t durationMs = 5000;

When this mode is active, the example calls saveRawByTime() and saves raw data for durationMs milliseconds.

(c) Size To save until a target byte size is reached, uncomment the Size line and comment out the currently active save mode.

// const std::string selected_savemode = "Size";
const std::uint64_t targetBytes = 100 * 1024 * 1024;

When this mode is active, the example calls saveRawBySize() and records until the saved data reaches targetBytes.

(d) EventCount To save until a target event count is reached, uncomment the EventCount line.

// const std::string selected_savemode = "EventCount";
const std::uint64_t targetEvents = 50000000;

When this mode is active, the example calls saveRawByEventCount().

(e) FrameCount To save until a target frame count is reached, uncomment the FrameCount line.

// const std::string selected_savemode = "FrameCount";
const std::uint64_t targetFrames = 5000;

When this mode is active, the example calls saveRawByFrameCount().

Note

Keep only one selected_savemode definition active. If more than one selected_savemode line is uncommented, the example will not compile because the same variable is defined multiple times.

Select the Save Directory

The sample saves raw data under saved_data/raw_data.

const std::filesystem::path saveDirectory =
    std::filesystem::path(DELTA_SAMPLE_ROOT) / "saved_data" / "raw_data";

Saved files use the .dvs format and can be opened later with openFile() in the playback examples.

Open the Device and Apply Sensor Settings

The device setup follows the same pattern as Device Connection.

std::int32_t deviceCount = 0;
delta::Status status = delta::scanDevices(&deviceCount);

delta::DeviceInfo deviceInfo{};
status = delta::getDeviceInfo(selectDeviceIndex, &deviceInfo);

delta::DeviceHandle cameraHandle = nullptr;
status = delta::openDevice(deviceInfo.index, &cameraHandle);
const std::filesystem::path settingFilePath =
    deviceInfo.type == delta::DeviceType::Delta_01
        ? std::filesystem::path(DELTA_SETTINGS_DIR) / "Delta_01_1000FPS.txt"
        : std::filesystem::path(DELTA_SETTINGS_DIR) / "Delta_10_2000FPS.txt";

const std::string settingFileString = settingFilePath.generic_string();
status = delta::applySensorSetting(cameraHandle, settingFileString.c_str());

Start Live Streaming

Raw saving requires live streaming to be active before calling any raw saving API.

status = delta::startStream(cameraHandle);

if (status != delta::Status::Success) {
    std::cout << "startStream failed: "
              << delta::getStatusMessage(status) << "\n";
    delta::closeDevice(cameraHandle);
    return 1;
}

Prepare the Save Directory

The sample creates the output directory before saving.

std::filesystem::create_directories(saveDirectory);
const std::string saveDirectoryString = saveDirectory.generic_string();

Save Raw Data

The selected save mode decides which raw saving API is called.

if (selected_savemode == "Continuous") {
    status = delta::startRawSaving(cameraHandle, saveDirectoryString.c_str());

    if (status == delta::Status::Success) {
        // Wait for the user to press 'q'.
        status = delta::stopRawSaving(cameraHandle);
    }
}
else if (selected_savemode == "Time") {
    status = delta::saveRawByTime(
        cameraHandle,
        saveDirectoryString.c_str(),
        durationMs
    );
}
else if (selected_savemode == "Size") {
    status = delta::saveRawBySize(
        cameraHandle,
        saveDirectoryString.c_str(),
        targetBytes
    );
}

The event-count and frame-count modes follow the same pattern.

status = delta::saveRawByEventCount(
    cameraHandle,
    saveDirectoryString.c_str(),
    targetEvents
);

status = delta::saveRawByFrameCount(
    cameraHandle,
    saveDirectoryString.c_str(),
    targetFrames
);

Stop Streaming

Stop the stream and close the device before the application exits.

delta::stopStream(cameraHandle);
delta::closeDevice(cameraHandle);