跳转到内容
STAGING SERVER
DEVELOPMENT SERVER

Compression Beyond#

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

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

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

该功能的使用#

运作原理#

只要 ImageCompressionMode 参数设置为 BaslerCompressionBeyond.

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

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

为了解决此问题,您必须告知相机其将 至少 能够压缩图像。通过指定压缩比(BslImageCompressionRatio 参数)来实现这一点。

例如,将 BslImageCompressionRatio 参数设置为 90,即告知相机它可以将任何图像压缩到其原始大小的至少 90%。利用此信息,相机可将帧率提高最多 10%。

但是,如果设置的值过低,即相机无法达到估计的压缩比,则会跳过帧。在这种情况下,您可以将 ImageCompressionRateOption 参数从 Lossless 变为 FixRatio。这允许实现甚至更低的压缩率,但会降低图像 Quality。

信息

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

    Compression Beyond 状态栏

  • 在实现自己的图像捕获例程时,必须使用 CImageDecompressor 类解压缩捕获的图像。如需了解详情,请参阅 pylon API 文档中的图像解压缩。

配置 Compression Beyond#

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

优化带宽#

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

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

为此:

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

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

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

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

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

为此:

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

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

信息

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

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

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

为此:

  1. 确保相机空闲,即未在捕获图像。
  2. 设置 ImageCompressionMode acquisition mode BaslerCompressionBeyond.
  3. 设置 ImageCompressionRateOption acquisition mode FixRatio.
  4. 设置 BslImageCompressionRatio acquisition mode 100.
  5. 至少采集一张图像。
  6. 获取 BslImageCompressionLastRatio 参数。
    该值表示无损和有损图像采集之间的阈值。
  7. 设置 BslImageCompressionRatio 参数设置为低于 BslImageCompressionLastRatio 参数。
    参数值越低,图像 Quality 越低。
  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 acquisition frame rate
double resultingFrameRate = camera.BslResultingAcquisitionFrameRate.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
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 acquisition frame rate
double resultingFrameRate = CFloatParameter(nodemap, "BslResultingAcquisitionFrameRate").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 acquisition frame rate
double resultingFrameRate = camera.Parameters[PLCamera.BslResultingAcquisitionFrameRate].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();
/* 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 acquisition frame rate */
errRes = PylonDeviceGetFloatFeature(hdev, "BslResultingAcquisitionFrameRate", &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);
# Enable Compression Beyond with lossless compression
camera.ImageCompressionMode.Value = "BaslerCompressionBeyond"
camera.ImageCompressionRateOption.Value = "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.Value = 70
# Get the resulting acquisition frame rate
resultingFrameRate = camera.BslResultingAcquisitionFrameRate.Value
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.Value = "FixRatio"
    camera.BslImageCompressionRatio.Value = 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
lastRatio = camera.BslImageCompressionLastRatio.Value
# Determine the payload size of the last acquired image in bytes
lastSize = camera.BslImageCompressionLastSize.Value

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