コンテンツにスキップ

Compression Beyond#

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

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

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

機能を使用する#

仕組み#

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. 少なくとも1枚の画像を取得します。
  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を使用して、パラメーターを簡単に設定することもできます。