Compression Beyond#
压缩图像数据可以降低相机的带宽使用率或提高帧速率,也可能同时实现这两个目标。
有关更多信息,请参见 Basler 网站上的功能描述。
该功能的使用#
运作原理#
只要将ImageCompressionMode
参数设置为BaslerCompressionBeyond
,即可自动执行压缩。
启用后,该功能始终尽可能地压缩图像。这降低了相机输出的数据量(“有效负载”),即其带宽使用率。这对于多相机设置中的 Basler GigE 相机尤其有用。
如果您希望相机还可优化帧速率,则需要进一步配置。这是因为相机在曝光开始之前无法“知道”它可以将图像压缩多少。
为了解决这个问题,您必须告诉相机至少可以将图像压缩到什么程度。通过指定压缩率(BslImageCompressionRatio
参数)来执行此操作。
例如,将 BslImageCompressionRatio
参数设置为 90,即意味着相机至少能够将任何图像压缩到其原始大小的 90%。根据此信息,相机可以将其帧速率提高多达 10 %。
但是,如果将该值设置得太低,即意味着相机无法达到预估的压缩率,将会跳过一些帧。在这种情况下,可以将 ImageCompressionRateOption
参数从 Lossless
更改为 FixRatio
。这支持更低的压缩率,但会降低图像质量。
信息
- 在图像采集期间,通过读取
BslImageCompressionLastRatio
和BslImageCompressionLastSize
参数值,可以确定最后采集的图像的有效负载大小和压缩率。 -
Compression Beyond 启用后,pylon Viewer 在图像显示区域的状态栏中会显示有关该功能的信息:
-
在实现自己的图像捕获例程时,必须使用 CImageDecompressor 类解压缩捕获的图像。如需了解详情,请参阅 pylon API 文档中的图像解压缩。
配置 Compression Beyond#
如何配置 Compression Beyond 取决于您的要求。
优化带宽#
如果您希望相机执行以下操作:
- 降低带宽使用率
- 提高帧速率
- 保持最佳图像质量
为此:
- 确保相机空闲,即未在捕获图像。
- 将
ImageCompressionMode
参数设置为BaslerCompressionBeyond
。 - 将
ImageCompressionRateOption
参数设置为Lossless
。 - 将
BslImageCompressionRatio
参数设置为 100。
通过这些设置,相机将在不牺牲图像质量的情况下尽可能地压缩图像。
通过无损压缩优化带宽和帧速率#
如果您希望相机执行以下操作:
- 降低带宽使用率
- 提高帧速率
- 保持最佳图像质量
为此:
- 确保相机空闲,即未在捕获图像。
- 将
ImageCompressionMode
参数设置为BaslerCompressionBeyond
。 - 将
ImageCompressionRateOption
参数设置为Lossless
。 - 将
BslImageCompressionRatio
参数设置为小于 100 的值,例如 90。 - Get the value of the
BslResultingAcquisitionFrameRate
parameter to determine the estimated frame rate. - 如果对于您的应用而言帧速率不够高,请使用较低的
BslImageCompressionRatio
参数值重复步骤 4 和 5。 - 开始图像采集。如果相机不跳过帧就无法采集图像,则无法获得所需的帧速率。请尝试以下操作:
- 如果可接受较低的帧速率,请增加
BslImageCompressionRatio
参数的值,直到相机能够连续采集图像为止。 - 如果可接受较低的图像质量,请执行以下详细步骤。
- 如果可接受较低的帧速率,请增加
通过有损压缩优化带宽和帧速率#
信息
始终首先尝试无损压缩。仅当无法通过无损压缩获得所需结果时,才使用有损压缩。
如果您希望相机执行以下操作:
- 降低带宽使用率
- 提高帧速率
- 保持最佳图像质量
为此:
- 确保相机空闲,即未在捕获图像。
- 将
ImageCompressionMode
参数设置为BaslerCompressionBeyond
。 - 将
ImageCompressionRateOption
参数设置为FixRatio
。 - 将
BslImageCompressionRatio
参数设置为100
。 - 至少采集一张图像。
- 获取
BslImageCompressionLastRatio
参数的值。
该值指示无损和有损图像采集之间的阈值。 - 将
BslImageCompressionRatio
参数值设置为低于BslImageCompressionLastRatio
参数值。
参数值越低,图像质量就越低。 - 开始图像采集。如果相机不跳过帧就无法采集图像,请增加
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 轻松设置参数。