Please enable JavaScript to view this site.

IDS peak 2.8.0 / uEye+ firmware 3.33

Navigation: C: Programming with IDS peak > How to program

Preparing image acquisition: Create buffer

Scroll Previous Top Next More

comfortSDK

The comfortSDK creates all necessary buffers when calling "peak_Acquisition_Start" if the buffers do not already exist.

comfortC

peak_status status = PEAK_STATUS_SUCCESS;
peak_camera_handle hCam = NULL;
status = peak_Camera_OpenFirstAvailable(&hCam);
if (PEAK_ERROR(status)) { /* Error handling ... */ }
 
// Buffers are automatically allocated in the following call:
status = peak_Acquisition_Start(hCam, PEAK_INFINITE);
if (PEAK_ERROR(status)) { /* Error handling ... */ }

genericSDK

To receive images from the camera, you must first create a DataStream object. Additionally, you create a NodeMap to access the nodes of the DataStream object (see Setting camera parameters).

genericC++

auto dataStreams = device->DataStreams();
if (dataStreams.empty())
{
  // no data streams available -> error
}
 
std::shared_ptr<DataStream> dataStream = device->DataStreams().at(0)->OpenDataStream();
std::shared_ptr<NodeMap> nodemapDataStream = dataStream->NodeMaps().at(0);

You can query the data volume required for a buffer via the PayloadSize node in the DataStream NodeMap. This buffer must be created so that the camera can transfer the image data to the IDS peak API after each captured image. PayloadSize depends on the image size, the source pixel format, and on whether additional information (chunks) on the image is transmitted besides the image data (see Setting ROI (region of interest) or Chunks (metadata)).

The image acquisition works with several buffers, at least 2 buffers are always required. While the image data is transferred to one buffer, the other buffer can be used by the application ("double buffering"). However, it is recommended to allocate more than 2 buffers. In this way, you can prevent images from being lost more effectively if, for example, the host system is briefly unable to process an image. If this happens, the number of concurrent buffers would go up for a short time until the host can retrieve the images. Note that this method can only handle short workload peaks, but not permanent overloads in the host system. The buffers are added to the so-called "buffer pool", from which the IDS peak API gets as required.

You can query how many buffers are required as a minimum for image acquisition via the dataStream->NumBuffersAnnouncedMinRequired() function. You can also use a larger number of buffers.

Creating buffers automatically by IDS peak API

1.Set the image size (see Setting ROI (region of interest)). This automatically defines the PayloadSize.

2.Query the PayloadSize (required size in bytes) for a buffer memory.

3.Query the minimum number of buffers required.

4.Allocate the buffer and announce it to the system ("AllocAndAnnounce").

5.Add the buffer to the "Buffer Pool" ("QueueBuffer").

genericC++

// Set ROI
// ...
 
if (dataStream)
{
  int64_t payloadSize = nodemapRemoteDevice->FindNode<peak::core::nodes::IntegerNode>("PayloadSize")->Value();
 
  // Get number of minimum required buffers
  int numBuffersMinRequired = dataStream->NumBuffersAnnouncedMinRequired();
 
  // Alloc buffers
  for (size_t count = 0; count < numBuffersMinRequired ; count++)
  {
      auto buffer = dataStream->AllocAndAnnounceBuffer(static_cast<size_t>(payloadSize), nullptr);
      dataStream->QueueBuffer(buffer);
  }
}

Remove and release buffers from the buffer pool at the end of image acquisition

genericC++

if (dataStream)
{
  dataStream->Flush(peak::core::DataStreamFlushMode::DiscardAll);
 
  for (const auto& buffer : dataStream->AnnouncedBuffers())
  {
      dataStream->RevokeBuffer(buffer);
  }
}

© 2024 IDS Imaging Development Systems GmbH