Frame Saving From Stream
This sample shows how to save generated ColorFrame output from a live DELTA
stream as BMP image files. Use this sample when you want rendered frame images
for quick inspection, dataset creation, or image-based tools.
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 | frameEndBased() / timeBased() / eventCountBased() |
Create a frame generation setting for saved BMP frames. |
| 4 | setOutputType() |
Select ColorFrame output for frame image saving. |
| 5 | setColorFormat() / setColor() |
Choose gray or RGB event visualization. |
| 6 | startStream() |
Start live USB streaming before saving frames. |
| 7 | startFrameSaving() / stopFrameSaving() |
Save frame images continuously until the user stops it. |
| 8 | saveFrameByTime() |
Save frame images for a fixed duration. |
| 9 | saveFrameByFrameCount() |
Save a fixed number of frame images. |
| 10 | stopStream() / closeDevice() |
Stop streaming and release the device. |
Code Walkthrough
Edit the User Control Panel
Select a Camera
const std::int32_t selectDeviceIndex = 0;
Select a Frame Generation Mode
Frame generation controls when each BMP frame is created. Only one
selected_framemode line should be active at a time.
const std::string selected_framemode = "FrameEndBased";
const std::int32_t frameEndCount = 1;
// const std::string selected_framemode = "TimeBased";
const std::int32_t framePeriodMs = 16;
// const std::string selected_framemode = "EventCountBased";
const std::int32_t eventsPerFrame = 150000;
FrameEndBased saves a generated frame after a selected number of frame-end
markers. TimeBased saves frames at a fixed time interval, and
EventCountBased saves a frame after a selected number of events.
Note
With high-FPS settings, BMP writing can become the bottleneck. For
Delta_10 at 2000 FPS, frameEndCount = 10 is a more stable starting point
than saving every generated frame.
Select a Frame Saving Mode
Only one selected_savemode line should be active at a time.
(a) Continuous
const std::string selected_savemode = "Continuous";
When this mode is active, press s to start frame saving and press q to stop
saving and quit. Internally, the example calls startFrameSaving() and
stopFrameSaving().
(b) Time
// const std::string selected_savemode = "Time";
const std::int32_t durationMs = 2000;
When this mode is active, the example calls saveFrameByTime().
(c) FrameCount
// const std::string selected_savemode = "FrameCount";
const std::uint64_t targetFrames = 500;
When this mode is active, the example calls saveFrameByFrameCount().
Note
Keep only one selected_savemode definition active. If more than one
selected_savemode line is uncommented, the example will not compile.
Select the Color Format
const std::string selected_colorformat = "Gray";
// const std::string selected_colorformat = "RGB";
const delta::EventColor rgbColor = {
{255, 0, 0}, // ON event color
{0, 0, 255}, // OFF event color
{255, 255, 255} // No event (background) color
};
Gray saves single-channel rendered frames. RGB saves three-channel rendered
frames and allows you to customize ON event, OFF event, and no-event colors with
rgbColor.
Select the Save Directory
const std::filesystem::path saveDirectory =
std::filesystem::path(DELTA_SAMPLE_ROOT) / "saved_data" / "frame_streaming";
Saved files use BMP format, one file per generated frame.
Create the Frame Generation Setting
Frame saving APIs receive a FrameGeneration value directly.
delta::FrameGeneration frameGeneration =
delta::frameEndBased(frameEndCount);
if (selected_framemode == "FrameEndBased") {
frameGeneration = delta::frameEndBased(frameEndCount);
}
else if (selected_framemode == "TimeBased") {
frameGeneration = delta::timeBased(framePeriodMs);
}
else if (selected_framemode == "EventCountBased") {
frameGeneration = delta::eventCountBased(eventsPerFrame);
}
Set Output Type and Color Format
Frame image saving writes BMP images generated from ColorFrame output.
status = delta::setOutputType(cameraHandle, delta::OutputType::ColorFrame);
if (selected_colorformat == "Gray") {
status = delta::setColorFormat(cameraHandle, delta::ColorFormat::Gray);
}
else if (selected_colorformat == "RGB") {
status = delta::setColorFormat(cameraHandle, delta::ColorFormat::RGB);
if (status == delta::Status::Success) {
status = delta::setColor(cameraHandle, &rgbColor);
}
}
Start Live Streaming
Frame image saving requires live streaming to be active first.
status = delta::startStream(cameraHandle);
Save Frame Images
The selected save mode decides which frame saving API is called.
if (selected_savemode == "Continuous") {
status = delta::startFrameSaving(
cameraHandle,
saveDirectoryString.c_str(),
frameGeneration
);
if (status == delta::Status::Success) {
// Wait for the user to press 'q'.
status = delta::stopFrameSaving(cameraHandle);
}
}
else if (selected_savemode == "Time") {
status = delta::saveFrameByTime(
cameraHandle,
saveDirectoryString.c_str(),
durationMs,
frameGeneration
);
}
else if (selected_savemode == "FrameCount") {
status = delta::saveFrameByFrameCount(
cameraHandle,
saveDirectoryString.c_str(),
targetFrames,
frameGeneration
);
}
Stop Streaming
delta::stopStream(cameraHandle);
delta::closeDevice(cameraHandle);