Compression Beyond#
画像データを圧縮すると、カメラの帯域幅使用量が減少するか、フレームレートが増加するか、またはその両方が発生する可能性があります。
詳細については、Basler Webサイトの機能の説明を参照してください。
機能を使用する#
仕組み#
圧縮は、 ImageCompressionMode パラメータが次のように設定されている場合、 BaslerCompressionBeyond.
この機能を有効にすると、画像は常に可能な限り圧縮されます。これにより、カメラによるデータ(「ペイロード」)出力の量(つまり、帯域幅の使用量)が減少します。これは、マルチカメラ設定のBasler GigEカメラに特に便利です。
カメラでフレームレートも最適化する場合は、さらに設定する必要があります。これは、露光開始前には画像を圧縮できる量がカメラに「わからない」ためです。
これを回避するには、カメラに対して 少なくとも 画像を圧縮できるよう指定する必要があります。これを行うには、圧縮比(BslImageCompressionRatio パラメータ)よりも高くする必要があります。
たとえば、 BslImageCompressionRatio パラメータを90に設定すると、カメラは任意の画像を元のサイズの少なくとも90%に圧縮できることを示します。この情報により、カメラはフレームレートを最大10%向上させることができます。
ただし、設定値が低すぎる場合、つまりカメラが推定圧縮率を達成できない場合、フレームがスキップされます。この場合、 ImageCompressionRateOption パラメータから Lossless ~ FixRatioを変更できます。これにより、さらに低い圧縮率が可能になりますが、image Qualityが低下します。
情報
- 画像取得中、最後に取得した画像のペイロードサイズと圧縮率は、
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)に設定します。 - の値を取得します。
BslResultingAcquisitionFrameRateパラメータを使用して、推定フレームレートを決定します。 - フレームレートがアプリケーションにとって十分でない場合は、より低い
BslImageCompressionRatioパラメータ値を確認する時間枠の開始点として使用します。 - 画像取得を開始します。フレームをスキップせずにカメラが画像を取得できない場合、希望するフレームレートを達成できません。次の操作を試してください。
- より低いフレームレート許容できる場合は、
BslImageCompressionRatioパラメータの値を、カメラが連続して画像を取得できるようになるまで増やします。 - 画質が低くても許容できる場合は、以下の手順を実行します。
- より低いフレームレート許容できる場合は、
ロッシー圧縮での帯域幅とフレームレートの最適化#
情報
必ずロスレス圧縮を最初に試してください。ロスレス圧縮で必要な結果を得られない場合にのみ、ロッシー圧縮を使用してください。
カメラで次の操作を行うとします。
- 帯域幅の使用量を減らします
- フレームレートを上げます
- 最適な画質を維持する
これを実現するには、次の手順に従います。
- カメラがアイドル状態であること、つまり画像をキャプチャしていないことを確認します。
- パラメーターを
ImageCompressionModeパラメータを次のように設定:BaslerCompressionBeyond. - パラメーターを
ImageCompressionRateOptionパラメータを次のように設定:FixRatio. - パラメーターを
BslImageCompressionRatioパラメータを次のように設定:100. - 少なくとも1枚の画像を取得します。
- の値を取得します。
BslImageCompressionLastRatioパラメータ。
この値は、ロスレス画像取得と非可逆画像取得の間のしきい値を示します。 - パラメーターを
BslImageCompressionRatioパラメータを、BslImageCompressionLastRatioパラメータ。
パラメータの値が低いほど、image Qualityは低下します。 - 画像取得を開始します。カメラがフレームをスキップせずに画像を取得できない場合は、
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を使用して、パラメーターを簡単に設定することもできます。