Compression Beyond#
壓縮影像資料可以降低相機的頻寬使用量、提高畫面更新率,或兩者兼具。
如需詳細資訊,請參閱 Basler 網站上的功能說明。
使用功能#
運作原理#
只要發生以下情況,就會自動執行壓縮: ImageCompressionMode 參數設為 BaslerCompressionBeyond.
啟用後,該功能總是會盡可能地壓縮影像。這會降低相機輸出的資料量(「負載」),也就是降低頻寬使用量。這對於在多相機設定中的 Basler GigE 相機特別有用。
如果您希望相機也能最佳化畫面更新率,則需要進行額外的設定。這是因為相機在曝光開始之前,並「不知道」能夠將影像壓縮多少。
為了克服這一點,您必須告知相機它將 至少 能夠壓縮影像。透過指定壓縮比來做到這點(BslImageCompressionRatio 參數)。
例如,將 BslImageCompressionRatio 參數設為 90,即表示相機將能夠把任何影像壓縮至其原始大小的至少 90%。有了這些資訊,相機就能將畫面更新率提高最多 10%。
然而,如果您設定的值過低,亦即相機無法達到預估的壓縮比,就會發生掉幀。在這種情況下,您可以變更 ImageCompressionRateOption 參數從 Lossless 設為 FixRatio。這允許更低的壓縮率,但會降低影像 Quality。
資訊
- 在影像擷取期間,您可以透過讀取以下內容來判定最後擷取之影像的負載大小與壓縮比:
BslImageCompressionLastRatio進行明確的生命週期管理即呼叫BslImageCompressionLastSize參數數值。 -
啟用 Compression Beyond 時,pylon Viewer 會在影像顯示區域的狀態列中顯示有關該功能的資訊:

-
當您實作自己的影像擷取常式時,必須使用 CImageDecompressor 類別來解壓縮擷取的影像。如需詳細資訊,請參閱 pylon API Documentation 中的 Image Decompression。
設定 Compression Beyond#
如何設定 Compression Beyond 取決於您的需求。
最佳化頻寬#
假設您希望相機執行以下操作:
- 降低頻寬使用量
- 提高畫面更新率
- 維持最佳影像 Quality
為達成此目的:
- 確保相機處於閒置狀態,即未擷取影像。
- 將相機中的
ImageCompressionMode參數設為BaslerCompressionBeyond. - 將相機中的
ImageCompressionRateOption參數設為Lossless. - 將相機中的
BslImageCompressionRatio參數設為 100。
透過這些設定,相機可以在不犧牲影像 Quality 的情況下盡可能地壓縮影像。
利用無損壓縮最佳化頻寬與影格率#
假設您希望相機執行以下操作:
- 降低頻寬使用量
- 提高畫面更新率
- 維持最佳影像 Quality
為達成此目的:
- 確保相機處於閒置狀態,即未擷取影像。
- 將相機中的
ImageCompressionMode參數設為BaslerCompressionBeyond. - 將相機中的
ImageCompressionRateOption參數設為Lossless. - 將相機中的
BslImageCompressionRatio將參數設為低於 100 的值,例如 90。 - 取得
BslResultingAcquisitionFrameRate此參數用於決定估計的影格率。 - 如果影格率不符合您的應用需求,請使用較低的數值重複步驟 4 和 5:
BslImageCompressionRatio參數值。 - 開始影像擷取。如果相機在擷取影像時出現掉格現象,則表示無法達到所需的影格率。請嘗試執行下列操作:
- 如果能接受較低的影格率,請增加
BslImageCompressionRatio參數的值,直到相機能夠連續擷取影像為止。 - 如果能接受較低的影像 Quality,請執行以下詳細程序。
- 如果能接受較低的影格率,請增加
利用有損壓縮最佳化頻寬與影格率#
資訊
請務必優先嘗試 無失真壓縮 (lossless compression)。只有在使用無失真壓縮無法達到所需結果時,才使用有損壓縮 (lossy compression)。
假設您希望相機執行以下操作:
- 降低頻寬使用量
- 提高畫面更新率
- 維持最佳影像 Quality
為達成此目的:
- 確保相機處於閒置狀態,即未擷取影像。
- 將相機中的
ImageCompressionMode參數設為BaslerCompressionBeyond. - 將相機中的
ImageCompressionRateOption參數設為FixRatio. - 將相機中的
BslImageCompressionRatio參數設為100. - 擷取至少一張影像。
- 取得
BslImageCompressionLastRatio參數中選擇性地指定 HTML 記錄檔 (*.html) 的路徑與檔名。
此數值表示無失真與有損影像擷取之間的閾值。 - 將相機中的
BslImageCompressionRatio參數設為小於BslImageCompressionLastRatio參數中選擇性地指定 HTML 記錄檔 (*.html) 的路徑與檔名。
參數值越低,影像 Quality 就越低。 - 開始影像擷取。如果相機在擷取影像時出現掉格現象,請增加
BslImageCompressionRatio參數的值,直到相機能夠順利擷取影像為止。
相較於無失真壓縮,使用這些設定或許能降低頻寬使用率並提高影格率,但這會降低影像 Quality。
範例程式碼#
// 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
您也可以 use the pylon Viewer 來輕鬆設定參數。