跳转到内容

Compression Beyond#

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

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

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

该功能的使用#

运作原理#

Compression is performed automatically whenever the ImageCompressionMode parameter is set to BaslerCompressionBeyond.

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

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

To get around this, you must tell the camera how much it will at least be able to compress images. Do this by specifying a compression ratio (BslImageCompressionRatio parameter).

For example, setting the BslImageCompressionRatio parameter to 90, tells the camera that it will be able to compress any image to at least 90 % of its original size. With this information, the camera can increase its frame rate by up to 10 %.

However, if you set the value too low, i.e., if the camera can't achieve the estimated compression ratio, frames will be skipped. In this case, you can change the ImageCompressionRateOption parameter from Lossless to FixRatio. This allows even lower compression rates, but reduces image quality.

信息

  • During image acquisition, you can determine the payload size and compression ratio of the last acquired image by reading the BslImageCompressionLastRatio and BslImageCompressionLastSize parameter values.
  • Compression Beyond 启用后,pylon Viewer 在图像显示区域的状态栏中会显示有关该功能的信息:

    Compression Beyond 状态栏

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

配置 Compression Beyond#

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

优化带宽#

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

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

为此:

  1. 确保相机空闲,即未在捕获图像。
  2. Set the ImageCompressionMode parameter to BaslerCompressionBeyond.
  3. Set the ImageCompressionRateOption parameter to Lossless.
  4. Set the BslImageCompressionRatio parameter to 100.

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

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

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

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

为此:

  1. 确保相机空闲,即未在捕获图像。
  2. Set the ImageCompressionMode parameter to BaslerCompressionBeyond.
  3. Set the ImageCompressionRateOption parameter to Lossless.
  4. Set the BslImageCompressionRatio parameter to a value lower than 100, e.g., 90.
  5. Get the value of the ResultingFrameRate parameter to determine the estimated frame rate.
  6. If the frame rate is not high enough for your application, repeat steps 4 and 5 with a lower BslImageCompressionRatio parameter value.
  7. 开始图像采集。如果相机不跳过帧就无法采集图像,则无法获得所需的帧速率。请尝试以下操作:
    • If a lower frame rate is acceptable, increase the value of the BslImageCompressionRatio parameter until the camera is able to acquire images continuously.
    • 如果可接受较低的图像质量,请执行以下详细步骤。

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

信息

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

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

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

为此:

  1. 确保相机空闲,即未在捕获图像。
  2. Set the ImageCompressionMode parameter to BaslerCompressionBeyond.
  3. Set the ImageCompressionRateOption parameter to FixRatio.
  4. Set the BslImageCompressionRatio parameter to 100.
  5. 至少采集一张图像。
  6. Get the value of the BslImageCompressionLastRatio parameter.
    The value indicates the threshold between lossless and lossy image acquisition.
  7. Set the BslImageCompressionRatio parameter to a value lower than the value of the BslImageCompressionLastRatio parameter.
    The lower the parameter value, the lower the image quality.
  8. Start image acquisition. If the camera can't acquire images without skipping frames, increase the value of the BslImageCompressionRatio parameter until the camera is able to acquire images.

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

示例代码#

// 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
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();
/* 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);
# 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 frame rate
resultingFrameRate = camera.ResultingFrameRate.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 轻松设置参数。