コンテンツにスキップ
ステージングサーバー
開発サーバー

Compression Beyond#

Compression Beyondカメラ機能を使用すると、カメラからの画像データ出力を圧縮できます。

画像データを圧縮すると、カメラの帯域幅使用量が減少するか、フレームレートが増加するか、またはその両方が発生する可能性があります。

詳細については、Basler Webサイトの機能の説明を参照してください。

機能を使用する#

仕組み#

圧縮は、 ImageCompressionMode パラメータが次のように設定されていること: BaslerCompressionBeyond.

この機能を有効にすると、画像は常に可能な限り圧縮されます。これにより、カメラによるデータ(「ペイロード」)出力の量(つまり、帯域幅の使用量)が減少します。これは、マルチカメラ設定のBasler GigEカメラに特に便利です。

カメラでフレームレートも最適化する場合は、さらに設定する必要があります。これは、露光開始前には画像を圧縮できる量がカメラに「わからない」ためです。

これを回避するには、カメラに対して 少なくとも 画像を圧縮できるよう指定する必要があります。これを行うには、圧縮率を指定します(BslImageCompressionRatio parameter)よりも高くする必要があります。

たとえば、 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 パラメータを BaslerCompressionBeyond.
  3. パラメーターを ImageCompressionRateOption パラメータを Lossless.
  4. パラメーターを BslImageCompressionRatio パラメータを 100 に設定します。

これらの設定を使用すると、画質を損なうことなく、カメラが画像を可能な限り圧縮します。

ロスレス圧縮での帯域幅とフレームレートの最適化#

カメラで次の操作を行うとします。

  • 帯域幅の使用量を減らします
  • フレームレートを上げます
  • 最適な画質を維持する

これを実現するには、次の手順に従います。

  1. カメラがアイドル状態であること、つまり画像をキャプチャしていないことを確認します。
  2. パラメーターを ImageCompressionMode パラメータを BaslerCompressionBeyond.
  3. パラメーターを ImageCompressionRateOption パラメータを Lossless.
  4. パラメーターを BslImageCompressionRatio パラメータを 100 未満の値(例:90)に設定します。
  5. 次の値を取得します。 BslResultingAcquisitionFrameRate パラメータを使用して、推定フレームレートを決定します。
  6. アプリケーションに対してフレームレートが十分に高くない場合は、 BslImageCompressionRatio パラメータ値を指定します。
  7. 画像取得を開始します。フレームをスキップせずにカメラが画像を取得できない場合、希望するフレームレートを達成できません。次の操作を試してください。
    • をさらに低くしてステップ 4 および 5 を繰り返します。より低いフレームレートが許容される場合は、 BslImageCompressionRatio パラメータの値を、カメラが継続的に画像を取得できるようになるまで増やします。
    • 画質が低くても許容できる場合は、以下の手順を実行します。

ロッシー圧縮での帯域幅とフレームレートの最適化#

情報

必ずロスレス圧縮を最初に試してください。ロスレス圧縮で必要な結果を得られない場合にのみ、ロッシー圧縮を使用してください。

カメラで次の操作を行うとします。

  • 帯域幅の使用量を減らします
  • フレームレートを上げます
  • 最適な画質を維持する

これを実現するには、次の手順に従います。

  1. カメラがアイドル状態であること、つまり画像をキャプチャしていないことを確認します。
  2. パラメーターを ImageCompressionMode パラメータを BaslerCompressionBeyond.
  3. パラメーターを ImageCompressionRateOption パラメータを FixRatio.
  4. パラメーターを BslImageCompressionRatio パラメータを 100.
  5. 少なくとも1枚の画像を取得します。
  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を使用して、パラメーターを簡単に設定することもできます。