跳转到内容

Compression Beyond#

相机的 Compression Beyond 功能可以让您压缩相机输出的图像数据。

压缩图像数据可以降低相机的带宽使用率或提高帧速率,也可能同时实现这两个目标。

有关更多信息,请参见 Basler 网站上的功能描述。

该功能的使用#

运作原理#

只要将ImageCompressionMode参数设置为BaslerCompressionBeyond,即可自动执行压缩。

启用后,该功能始终尽可能地压缩图像。这降低了相机输出的数据量(“有效负载”),即其带宽使用率。这对于多相机设置中的 Basler GigE 相机尤其有用。

如果您希望相机还可优化帧速率,则需要进一步配置。这是因为相机在曝光开始之前无法“知道”它可以将图像压缩多少。

为了解决这个问题,您必须告诉相机至少可以将图像压缩到什么程度。通过指定压缩率(BslImageCompressionRatio 参数)来执行此操作。

例如,将 BslImageCompressionRatio 参数设置为 90,即意味着相机至少能够将任何图像压缩到其原始大小的 90%。根据此信息,相机可以将其帧速率提高多达 10 %。

但是,如果将该值设置得太低,即意味着相机无法达到预估的压缩率,将会跳过一些帧。在这种情况下,可以将 ImageCompressionRateOption 参数从 Lossless 更改为 FixRatio。这支持更低的压缩率,但会降低图像质量。

信息

  • 在图像采集期间,通过读取 BslImageCompressionLastRatioBslImageCompressionLastSize 参数值,可以确定最后采集的图像的有效负载大小和压缩率。
  • Compression Beyond 启用后,pylon Viewer 在图像显示区域的状态栏中会显示有关该功能的信息:

    Compression Beyond Status Bar

  • 在实施自己的图像捕获例程时,必须使用 CImageDecompressor 类解压缩捕获的图像。有关更多信息,请参见 C++ 程序员指南和参考文档(随 Basler pylon Camera Software Suite 一起提供)的“高级主题”主题中的“图像解压缩”部分。

配置 Compression Beyond#

如何配置 Compression Beyond 取决于您的要求。

优化带宽#

如果您希望相机执行以下操作:

  • 降低带宽使用率
  • 提高帧速率
  • 保持最佳图像质量

为此:

  1. 确保相机空闲,即未在捕获图像。
  2. ImageCompressionMode 参数设置为 BaslerCompressionBeyond
  3. ImageCompressionRateOption 参数设置为 Lossless
  4. BslImageCompressionRatio 参数设置为 100。

通过这些设置,相机将在不牺牲图像质量的情况下尽可能地压缩图像。

通过无损压缩优化带宽和帧速率#

如果您希望相机执行以下操作:

  • 降低带宽使用率
  • 提高帧速率
  • 保持最佳图像质量

为此:

  1. 确保相机空闲,即未在捕获图像。
  2. ImageCompressionMode 参数设置为 BaslerCompressionBeyond
  3. ImageCompressionRateOption 参数设置为 Lossless
  4. BslImageCompressionRatio 参数设置为小于 100 的值,例如 90。
  5. 获取 ResultingFrameRate 参数的值,以确定预估的帧速率。
  6. 如果对于您的应用而言帧速率不够高,请使用较低的 BslImageCompressionRatio 参数值重复步骤 4 和 5。
  7. 开始图像采集。如果相机不跳过帧就无法采集图像,则无法获得所需的帧速率。请尝试以下操作:
    • 如果可接受较低的帧速率,请增加 BslImageCompressionRatio 参数的值,直到相机能够连续采集图像为止。
    • 如果可接受较低的图像质量,请执行以下详细步骤。

通过有损压缩优化带宽和帧速率#

信息

始终首先尝试无损压缩。仅当无法通过无损压缩获得所需结果时,才使用有损压缩。

如果您希望相机执行以下操作:

  • 降低带宽使用率
  • 提高帧速率
  • 保持最佳图像质量

为此:

  1. 确保相机空闲,即未在捕获图像。
  2. ImageCompressionMode 参数设置为 BaslerCompressionBeyond
  3. ImageCompressionRateOption 参数设置为 FixRatio
  4. BslImageCompressionRatio 参数设置为 100
  5. 至少采集一张图像。
  6. 获取 BslImageCompressionLastRatio 参数的值。
    该值指示无损和有损图像采集之间的阈值。
  7. BslImageCompressionRatio 参数值设置为低于 BslImageCompressionLastRatio 参数值。
    参数值越低,图像质量就越低。
  8. 开始图像采集。如果相机不跳过帧就无法采集图像,请增加 BslImageCompressionRatio 参数的值,直到相机能够采集图像为止。

通过这些设置,与无损压缩相比,您或许能够降低带宽使用率和提高帧速率。但是,这会降低图像质量。

示例代码#

// Enable Compression Beyond with lossless compression
camera.ImageCompressionMode.SetValue(ImageCompressionMode_BaslerCompressionBeyond);
camera.ImageCompressionRateOption.SetValue(ImageCompressionRateOption_Lossless);
// To increase the frame rate, tell the camera that it will be able
// to compress any image to at least 70 % of its original size
camera.BslImageCompressionRatio.SetValue(70);
// Get the resulting frame rate
double resultingFrameRate = camera.ResultingFrameRate.GetValue();
if (resultingFrameRate < desiredFrameRate) {
    // Frame rate isn't high enough for the application.
    // Therefore, enable lossy compression. This allows even
    // lower compression rates, but reduces image quality.
    camera.ImageCompressionRateOption.SetValue(ImageCompressionRateOption_FixRatio);
    camera.BslImageCompressionRatio.SetValue(50);
}
// Start image acquisition
// ...
// (Implement your own image grabbing routine here.
// For example, the InstantCamera class provides the StartGrabbing() method.
// Note that you must decompress grabbed images using the CImageDecompressor class.)
// ...
// Determine the compression ratio of the last acquired image
double lastRatio = camera.BslImageCompressionLastRatio.GetValue();
// Determine the payload size of the last acquired image in bytes
int64_t lastSize = camera.BslImageCompressionLastSize.GetValue();
INodeMap& nodemap = camera.GetNodeMap();
// Enable Compression Beyond with lossless compression
CEnumerationPtr(nodemap.GetNode("ImageCompressionMode"))->FromString("BaslerCompressionBeyond");
CEnumerationPtr(nodemap.GetNode("ImageCompressionRateOption"))->FromString("Lossless");
// To increase the frame rate, tell the camera that it will be able
// to compress any image to at least 70 % of its original size
CIntegerPtr(nodemap.GetNode("BslImageCompressionRatio"))->SetValue(70);
// Get the resulting frame rate
double resultingFrameRate = CFloatPtr(nodemap.GetNode("ResultingFrameRate"))->GetValue();
if(resultingFrameRate < desiredFrameRate){
    // Frame rate isn't high enough for the application.
    // Therefore, enable lossy compression. This allows even
    // lower compression rates, but reduces image quality.
    CEnumerationPtr(nodemap.GetNode("ImageCompressionRateOption"))->FromString("FixRatio");
    CIntegerPtr(nodemap.GetNode("BslImageCompressionRatio"))->SetValue(50);
}
// Start image acquisition
// ...
// (Implement your own image grabbing routine here.
// For example, the InstantCamera class provides the StartGrabbing() method.
// Note that you must decompress grabbed images using the CImageDecompressor class.)
// ...
// Determine the compression ratio of the last acquired image
double lastRatio = CFloatPtr(nodemap.GetNode("BslImageCompressionLastRatio"))->GetValue();
// Determine the payload size of the last acquired image in bytes
int64_t lastSize = CIntegerPtr(nodemap.GetNode("BslImageCompressionLastSize"))->GetValue();
INodeMap& nodemap = camera.GetNodeMap();
// Enable Compression Beyond with lossless compression
CEnumParameter(nodemap, "ImageCompressionMode").SetValue("BaslerCompressionBeyond");
CEnumParameter(nodemap, "ImageCompressionRateOption").SetValue("Lossless");
// To increase the frame rate, tell the camera that it will be able
// to compress any image to at least 70 % of its original size
CIntegerParameter(nodemap, "BslImageCompressionRatio").SetValue(70);
// Get the resulting frame rate
double resultingFrameRate = CFloatParameter(nodemap, "ResultingFrameRate").GetValue();
if(resultingFrameRate < desiredFrameRate){
    // Frame rate isn't high enough for the application.
    // Therefore, enable lossy compression. This allows even
    // lower compression rates, but reduces image quality.
    CEnumParameter(nodemap, "ImageCompressionRateOption").SetValue("FixRatio");
    CIntegerParameter(nodemap, "BslImageCompressionRatio").SetValue(50);
}
// Start image acquisition
// ...
// (Implement your own image grabbing routine here.
// For example, the InstantCamera class provides the StartGrabbing() method.
// Note that you must decompress grabbed images using the CImageDecompressor class.)
// ...
// Determine the compression ratio of the last acquired image
double lastRatio = CFloatParameter(nodemap, "BslImageCompressionLastRatio").GetValue();
// Determine the payload size of the last acquired image in bytes
int64_t lastSize = CIntegerParameter(nodemap, "BslImageCompressionLastSize").GetValue();
// Enable Compression Beyond with lossless compression
camera.Parameters[PLCamera.ImageCompressionMode].SetValue(PLCamera.ImageCompressionMode.BaslerCompressionBeyond);
camera.Parameters[PLCamera.ImageCompressionRateOption].SetValue(PLCamera.ImageCompressionRateOption.Lossless);
// To increase the frame rate, tell the camera that it will be able
// to compress any image to at least 70 % of its original size
camera.Parameters[PLCamera.BslImageCompressionRatio].SetValue(70);
// Get the resulting frame rate
double resultingFrameRate = camera.Parameters[PLCamera.ResultingFrameRate].GetValue();
if(resultingFrameRate < desiredFrameRate){
    // Frame rate isn't high enough for the application.
    // Therefore, enable lossy compression. This allows even
    // lower compression rates, but reduces image quality.
    camera.Parameters[PLCamera.ImageCompressionRateOption].SetValue(PLCamera.ImageCompressionRateOption.FixRatio);
    camera.Parameters[PLCamera.BslImageCompressionRatio].SetValue(50);
}
// Start image acquisition
// ...
// (Implement your own image grabbing routine here.
// For example, the InstantCamera class provides the StartGrabbing() method.
// Note that you must decompress grabbed images using the CImageDecompressor class.)
// ...
// Determine the compression ratio of the last acquired image
double lastRatio = camera.Parameters[PLCamera.BslImageCompressionLastRatio].GetValue();
// Determine the payload size of the last acquired image in bytes
Int64 lastSize = camera.Parameters[PLCamera.BslImageCompressionLastSize].GetValue();
// Enable Compression Beyond with lossless compression
Pylon.DeviceFeatureFromString(hdev, "ImageCompressionMode", "BaslerCompressionBeyond");
Pylon.DeviceFeatureFromString(hdev, "ImageCompressionRateOption", "Lossless");
// To increase the frame rate, tell the camera that it will be able
// to compress any image to at least 70 % of its original size
Pylon.DeviceSetIntegerFeature(hdev, "BslImageCompressionRatio", 70);
// Get the resulting frame rate
double resultingFrameRate = Pylon.DeviceGetFloatFeature(hdev, "ResultingFrameRate");
if(resultingFrameRate < desiredFrameRate){
    // Frame rate isn't high enough for the application.
    // Therefore, enable lossy compression. This allows even
    // lower compression rates, but reduces image quality.
    Pylon.DeviceFeatureFromString(hdev, "ImageCompressionRateOption", "FixRatio");
    Pylon.DeviceSetIntegerFeature(hdev, "BslImageCompressionRatio", 50);
}
// Start image acquisition
// ...
// (Implement your own image grabbing routine here.
// For example, the InstantCamera class provides the StartGrabbing() method.
// Note that you must decompress grabbed images using the CImageDecompressor class.)
// ...
// Determine the compression ratio of the last acquired image
double lastRatio = Pylon.DeviceGetFloatFeature(hdev, "BslImageCompressionLastRatio");
// Determine the payload size of the last acquired image in bytes
Int64 lastSize = Pylon.DeviceGetIntegerFeature(hdev, "BslImageCompressionLastSize");
/* Macro to check for errors */
#define CHECK(errc) if (GENAPI_E_OK != errc) printErrorAndExit(errc)
GENAPIC_RESULT errRes = GENAPI_E_OK;  /* Return value of pylon methods */
double resultingFrameRate = 0;
double lastRatio = 0;
int64_t lastSize = 0;
/* Enable Compression Beyond with lossless compression */
errRes = PylonDeviceFeatureFromString(hdev, "ImageCompressionMode", "BaslerCompressionBeyond");
CHECK(errRes);
errRes = PylonDeviceFeatureFromString(hdev, "ImageCompressionRateOption", "Lossless");
CHECK(errRes);
/* To increase the frame rate, tell the camera that it will be able */
/* to compress any image to at least 70 % of its original size */
errRes = PylonDeviceSetIntegerFeature(hdev, "BslImageCompressionRatio", 70);
CHECK(errRes);
/* Get the resulting frame rate */
errRes = PylonDeviceGetFloatFeature(hdev, "ResultingFrameRate", &resultingFrameRate);
CHECK(errRes);
if(resultingFrameRate < desiredFrameRate){
    /* Frame rate isn't high enough for the application. */
    /* Therefore, enable lossy compression. This allows even */
    /* lower compression rates, but reduces image quality. */
    errRes = PylonDeviceFeatureFromString(hdev, "ImageCompressionRateOption", "FixRatio");
    CHECK(errRes);
    errRes = PylonDeviceSetIntegerFeature(hdev, "BslImageCompressionRatio", 50);
    CHECK(errRes);
}
/* Start image acquisition */
/* ... */
/* (Implement your own image grabbing routine here. */
/* For example, the InstantCamera class provides the StartGrabbing() method. */
/* Note that you must decompress grabbed images using the CImageDecompressor class.) */
/* ... */
/* Determine the compression ratio of the last acquired image */
errRes = PylonDeviceGetFloatFeature(hdev, "BslImageCompressionLastRatio", &lastRatio);
CHECK(errRes);
/* Determine the payload size of the last acquired image in bytes */
errRes = PylonDeviceGetIntegerFeature(hdev, "BslImageCompressionLastSize", &lastSize);
CHECK(errRes);

您也可以使用 pylon Viewer 轻松设置参数。