Zivid C++ API 2.18.0+1b44dbef-1
Zivid::Frame2D Class Reference

A 2D frame captured by a Zivid camera. More...

#include <Zivid/Frame2D.h>

Public Member Functions

ZIVID_CORE_EXPORT Frame2D ()
 Construct a new empty 2d frame.
ZIVID_CORE_EXPORT Image< ColorRGBAimageRGBA () const
 Get color (RGBA) image from the frame.
ZIVID_CORE_EXPORT Image< ColorBGRAimageBGRA () const
 Get color (BGRA) image from the frame.
ZIVID_CORE_EXPORT Image< ColorRGBA_SRGBimageSRGB () const
 Get color (RGBA in the sRGB color space) image from the frame.
ZIVID_CORE_EXPORT Image< ColorRGBA_SRGBimageRGBA_SRGB () const
 Get color (RGBA in the sRGB color space) image from the frame.
ZIVID_CORE_EXPORT Image< ColorBGRA_SRGBimageBGRA_SRGB () const
 Get color (BGRA in the sRGB color space) image from the frame.
ZIVID_CORE_EXPORT Image< ColorRGBimageRGB () const
 Get color (RGB, 3-channel, no alpha) image from the frame.
ZIVID_CORE_EXPORT Image< ColorRGB_SRGBimageRGB_SRGB () const
 Get color (RGB in the sRGB color space, 3-channel, no alpha) image from the frame.
ZIVID_CORE_EXPORT Image< ColorBGRimageBGR () const
 Get color (BGR, 3-channel, no alpha) image from the frame.
ZIVID_CORE_EXPORT Image< ColorBGR_SRGBimageBGR_SRGB () const
 Get color (BGR in the sRGB color space, 3-channel, no alpha) image from the frame.
template<typename ColorFormat, typename = std::enable_if_t<Detail::SupportedImageDeviceArrayColorFormat<ColorFormat>::value>>
ZIVID_CORE_EXPORT DeviceArray< ColorFormat > imageDeviceArray (StreamOrQueue streamOrQueue) const
 Get a GPU device buffer of the image in the specified format.
template<typename ColorFormat, typename = std::enable_if_t<Detail::SupportedImageDeviceArrayColorFormat<ColorFormat>::value>>
ZIVID_CORE_EXPORT void imageDeviceArray (DeviceArrayView< ColorFormat > destinationBuffer, StreamOrQueue streamOrQueue) const
 Fill a user-provided DeviceArrayView with the image in the specified format.
ZIVID_CORE_EXPORT Settings2D settings () const
 Get the settings used to capture this frame.
ZIVID_CORE_EXPORT CameraState state () const
 Get the camera state data at the time of the capture.
ZIVID_CORE_EXPORT FrameInfo info () const
 Get information collected at the time of the capture.
ZIVID_CORE_EXPORT CameraInfo cameraInfo () const
 Get information about the camera used to capture the frame.
ZIVID_CORE_EXPORT std::string toString () const
 Get string representation of the frame.
ZIVID_CORE_EXPORT Frame2D clone () const
 Returns a clone of the frame. The clone will include a copy of all of the frame data.
ZIVID_CORE_EXPORT void save (const std::string &fileName) const
 Save the frame to a .zdf file.
ZIVID_CORE_EXPORT void load (const std::string &fileName)
 Load a frame from a .zdf file.
ZIVID_CORE_EXPORT Frame2D (const std::string &fileName)
 Construct a Frame2D by loading from a .zdf file.

Detailed Description

A 2D frame captured by a Zivid camera.

Contains a 2D image as well as metadata, settings and state of the API at the time of capture.

Note that if this Frame2D object was returned from a call to Camera::capture, then there may still be remaining data transfer and processing going on in the background. When you call a method on the Frame2D object that requires the capture to be finished, for example Frame2D::imageRGBA(), the method will block until the image is available.

The images are not corrected for lens distortion. If your application relies on the geometry of the image, you can undistort it using the camera intrinsics.

Constructor & Destructor Documentation

◆ Frame2D() [1/2]

ZIVID_CORE_EXPORT Zivid::Frame2D::Frame2D ( )

Construct a new empty 2d frame.

◆ Frame2D() [2/2]

ZIVID_CORE_EXPORT Zivid::Frame2D::Frame2D ( const std::string & fileName)
explicit

Construct a Frame2D by loading from a .zdf file.

Parameters
fileNamePath to the .zdf file to load

Member Function Documentation

◆ cameraInfo()

ZIVID_CORE_EXPORT CameraInfo Zivid::Frame2D::cameraInfo ( ) const

Get information about the camera used to capture the frame.

This method returns instantly, even if the capture is still in-progress.

◆ clone()

ZIVID_CORE_EXPORT Frame2D Zivid::Frame2D::clone ( ) const

Returns a clone of the frame. The clone will include a copy of all of the frame data.

This function incurs a performance cost due to the copying of the data. When performance is important we recommend to avoid using this method, and instead modify the existing frame.

◆ imageBGR()

ZIVID_CORE_EXPORT Image< ColorBGR > Zivid::Frame2D::imageBGR ( ) const

Get color (BGR, 3-channel, no alpha) image from the frame.

◆ imageBGR_SRGB()

ZIVID_CORE_EXPORT Image< ColorBGR_SRGB > Zivid::Frame2D::imageBGR_SRGB ( ) const

Get color (BGR in the sRGB color space, 3-channel, no alpha) image from the frame.

◆ imageBGRA()

ZIVID_CORE_EXPORT Image< ColorBGRA > Zivid::Frame2D::imageBGRA ( ) const

Get color (BGRA) image from the frame.

The format of each pixel is given by ColorBGRA.

This format holds linear color values, which are suitable as input to computer vision algorithms. For showing colors on a display for viewing, consider using the ColorRGBA_SRGB format.

If the image is not yet available because the capture is still in-progress, then this method will block until the image is available.

◆ imageBGRA_SRGB()

ZIVID_CORE_EXPORT Image< ColorBGRA_SRGB > Zivid::Frame2D::imageBGRA_SRGB ( ) const

Get color (BGRA in the sRGB color space) image from the frame.

The sRGB color space is suitable for showing an image on a display for human viewing. It is easier to see details in darker areas of an image in sRGB than in linear RGB, as more of the dynamic range is dedicated to darker colors. This format is assumed by default by most monitors and should be used when displaying an image.

The format of each pixel is given by ColorBGRA_SRGB.

If the image is not yet available because the capture is still in-progress, then this method will block until the image is available.

◆ imageDeviceArray() [1/2]

template<typename ColorFormat, typename = std::enable_if_t<Detail::SupportedImageDeviceArrayColorFormat<ColorFormat>::value>>
ZIVID_CORE_EXPORT void Zivid::Frame2D::imageDeviceArray ( DeviceArrayView< ColorFormat > destinationBuffer,
StreamOrQueue streamOrQueue ) const

Fill a user-provided DeviceArrayView with the image in the specified format.

Template Parameters
ColorFormatTarget color format (ColorRGBA, ColorRGBA_SRGB, ColorBGRA, ColorBGRA_SRGB, or ColorRGBAf).
Parameters
destinationBufferNon-owning view over the destination device memory, typically constructed via createDeviceArrayView from a caller-owned pointer, or borrowed implicitly from a DeviceArray.
streamOrQueueUser CUDA stream or OpenCL command queue to synchronize the completion of the color conversion on. Pass either a CUDAStreamPtr or OpenCLCommandQueuePtr; conversion is implicit.

Writes the frame's image directly into the memory referenced by the view, bypassing the SDK's internal cache. Throws an exception if the view shape does not match the frame dimensions. The caller's stream/queue carries a barrier against the SDK compute on return, so consumer work can be enqueued on the same stream immediately.

◆ imageDeviceArray() [2/2]

template<typename ColorFormat, typename = std::enable_if_t<Detail::SupportedImageDeviceArrayColorFormat<ColorFormat>::value>>
ZIVID_CORE_EXPORT DeviceArray< ColorFormat > Zivid::Frame2D::imageDeviceArray ( StreamOrQueue streamOrQueue) const

Get a GPU device buffer of the image in the specified format.

Template Parameters
ColorFormatTarget color format (ColorRGBA, ColorRGBA_SRGB, ColorBGRA, ColorBGRA_SRGB, or ColorRGBAf)
Returns
DeviceArray containing the image in the requested format

This method provides access to the image data on the GPU. If the requested format matches the internal format, the buffer is returned directly without conversion. Otherwise, a format conversion is performed on the GPU.

The buffer is reference-counted and holds a reference to the underlying device memory, ensuring it remains valid for the lifetime of the buffer object. The buffer can be safely copied, and all copies will share ownership of the underlying device memory. The device memory is automatically released when the last reference is destroyed.

The device pointer obtained from the buffer can be used with GPU compute frameworks (such as CUDA), passed to GPU-aware libraries (like cuDNN or GStreamer CUDA elements), or used for zero-copy interop with other GPU frameworks.

If the image is not yet available because the capture is still in progress, then this method will block until the image is available.

Example usage:

// Get buffer in RGBA8 format, synchronized on the user's CUDA stream.
auto rgba8Buffer = frame2d.imageDeviceArray<ColorRGBA>(CUDAStreamPtr{ stream });
auto image = Zivid::toImage(rgba8Buffer); // Image<ColorRGBA>
// OpenCL callers pass OpenCLCommandQueuePtr instead; implicit conversion picks the right backend.
auto floatBuffer = frame2d.imageDeviceArray<ColorRGBAf>(OpenCLCommandQueuePtr{ queue });
Image< ColorFormat > toImage(const DeviceArray< ColorFormat > &buffer, StreamOrQueue streamOrQueue)
Enqueue a device-to-host copy and return as Image without synchronizing.
Definition DeviceArray.h:451
Wrapper for user-provided CUDA stream for synchronization.
Definition ComputeWrappers.h:85
Color with 8-bit red, green, blue and alpha channels.
Definition Color.h:189
Color with 32-bit red, green, blue and alpha channels.
Definition Color.h:285
Wrapper for user-provided OpenCL command queue for synchronization.
Definition ComputeWrappers.h:75

◆ imageRGB()

ZIVID_CORE_EXPORT Image< ColorRGB > Zivid::Frame2D::imageRGB ( ) const

Get color (RGB, 3-channel, no alpha) image from the frame.

The format of each pixel is given by ColorRGB. Identical to imageRGBA but skips the alpha channel for ~25% bandwidth savings.

◆ imageRGB_SRGB()

ZIVID_CORE_EXPORT Image< ColorRGB_SRGB > Zivid::Frame2D::imageRGB_SRGB ( ) const

Get color (RGB in the sRGB color space, 3-channel, no alpha) image from the frame.

◆ imageRGBA()

ZIVID_CORE_EXPORT Image< ColorRGBA > Zivid::Frame2D::imageRGBA ( ) const

Get color (RGBA) image from the frame.

The format of each pixel is given by ColorRGBA.

This format holds linear color values, which are suitable as input to computer vision algorithms. For showing colors on a display for viewing, consider using the ColorRGBA_SRGB format.

If the image is not yet available because the capture is still in-progress, then this method will block until the image is available.

◆ imageRGBA_SRGB()

ZIVID_CORE_EXPORT Image< ColorRGBA_SRGB > Zivid::Frame2D::imageRGBA_SRGB ( ) const

Get color (RGBA in the sRGB color space) image from the frame.

The sRGB color space is suitable for showing an image on a display for human viewing. It is easier to see details in darker areas of an image in sRGB than in linear RGB, as more of the dynamic range is dedicated to darker colors. This format is assumed by default by most monitors and should be used when displaying an image.

The format of each pixel is given by ColorRGBA_SRGB.

If the image is not yet available because the capture is still in-progress, then this method will block until the image is available.

◆ imageSRGB()

ZIVID_CORE_EXPORT Image< ColorRGBA_SRGB > Zivid::Frame2D::imageSRGB ( ) const

Get color (RGBA in the sRGB color space) image from the frame.

The sRGB color space is suitable for showing an image on a display for human viewing. It is easier to see details in darker areas of an image in sRGB than in linear RGB, as more of the dynamic range is dedicated to darker colors. This format is assumed by default by most monitors and should be used when displaying an image.

The format of each pixel is given by ColorRGBA_SRGB. If the image is not yet available because the capture is still in-progress, then this method will block until the image is available.

This method has been deprecated as of SDK 2.15. The method will be removed in the next SDK major version (SDK 3.0). Prefer to use the new and equivalent method imageRGBA_SRGB.

◆ info()

ZIVID_CORE_EXPORT FrameInfo Zivid::Frame2D::info ( ) const

Get information collected at the time of the capture.

If the capture is still in-progress, then this method will block until the capture completes.

◆ load()

ZIVID_CORE_EXPORT void Zivid::Frame2D::load ( const std::string & fileName)

Load a frame from a .zdf file.

Use Zivid::readFrameFileType to determine the frame type without loading. This method will throw an exception if the frame type is not frame2D.

Parameters
fileNamePath to the .zdf file to load

◆ save()

ZIVID_CORE_EXPORT void Zivid::Frame2D::save ( const std::string & fileName) const

Save the frame to a .zdf file.

Parameters
fileNamePath to the output .zdf file

◆ settings()

ZIVID_CORE_EXPORT Settings2D Zivid::Frame2D::settings ( ) const

Get the settings used to capture this frame.

This method returns instantly, even if the capture is still in-progress.

◆ state()

ZIVID_CORE_EXPORT CameraState Zivid::Frame2D::state ( ) const

Get the camera state data at the time of the capture.

If the capture is still in-progress, then this method will block until the capture completes.

◆ toString()

ZIVID_CORE_EXPORT std::string Zivid::Frame2D::toString ( ) const

Get string representation of the frame.

Returns
Frame info as string

If the capture is still in-progress, then this method will block until the capture completes.


The documentation for this class was generated from the following file: