跳至內容
測試伺服器
開發伺服器

Scaling#

使用 Scaling 相機功能,您可以對影像進行放大與縮小。

使用此功能#

運作原理#

Scaling 功能引入了一個可使用 BslScalingFactor 參數進行縮放的虛擬感光元件平面。其中的 BslScaledSensorWidth 和 BslScaledSensorHeight 參數表示虛擬感光元件目前的大小。

  • 較低的縮放比例會增加虛擬感光元件的大小。
  • 較高的縮放比例會減少虛擬感光元件的大小。

公式

虛擬感光元件大小 = 實體感光元件大小 / BslScalingFactor

範例: 假設您的相機感光元件解析度為 2592 x 1944 像素。如果您將 BslScalingFactor 參數設定為 0.5,虛擬感光元件的大小將是實體感光元件的兩倍,也就是 5184 x 3888 像素。

放大#

若要放大,請將 BslScalingFactor 參數設定為 lower 小於 1.0 的值。

這會增加虛擬感光元件的大小,同時保持 Image ROI 的大小與位置不變。

範例: 在以下範例中, BslScalingFactor 參數設定為 0.5。虛擬感光元件的大小減半,而 Image ROI 的大小與位置維持不變。

因此,影像內容會呈現放大並向左上方偏移的效果。

範例:放大

縮小#

若要縮小,請將 BslScalingFactor 參數設定為 較高 小於 1.0 的值。

這會減少虛擬感光元件的大小,同時保持 Image ROI 的大小與位置不變。

資訊

虛擬感光元件的大小不得小於 Image ROI。

因此,您可能需要在縮小之前先減小 Image ROI 的高度與寬度。

範例: 在以下範例中, BslScalingFactor 參數設定為 2.0。虛擬感光元件的大小加倍,而 Image ROI 的大小與位置維持不變。

因此,影像內容會呈現縮小並向右下方偏移的效果。

範例:縮小

範例程式碼#

// Set scaling to 0.5, i.e., set the size of the
// virtual sensor to 2x the size of the physical sensor
camera.BslScalingFactor.SetValue(0.5);
// Get the size of the virtual sensor
double scaledWidth = camera.BslScaledSensorWidth.GetValue();
double scaledHeight = camera.BslScaledSensorHeight.GetValue();
// Disable scaling
camera.BslScalingFactor.SetValue(1.0);
INodeMap& nodemap = camera.GetNodeMap();
// Set scaling to 0.5, i.e., set the size of the
// virtual sensor to 2x the size of the physical sensor
CFloatParameter(nodemap, "BslScalingFactor").SetValue(0.5);
// Get the size of the virtual sensor
double scaledWidth = CFloatParameter(nodemap, "BslScaledSensorWidth").GetValue();
double scaledHeight = CFloatParameter(nodemap, "BslScaledSensorHeight").GetValue();
// Disable scaling
CFloatParameter(nodemap, "BslScalingFactor").SetValue(1.0);
// Set scaling to 0.5, i.e., set the size of the
// virtual sensor to 2x the size of the physical sensor
camera.Parameters[PLCamera.BslScalingFactor].SetValue(0.5);
// Get the size of the virtual sensor
double scaledWidth = camera.Parameters[PLCamera.BslScaledSensorWidth].GetValue();
double scaledHeight = camera.Parameters[PLCamera.BslScaledSensorHeight].GetValue();
// Disable scaling
camera.Parameters[PLCamera.BslScalingFactor].SetValue(1.0);
/* 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 scaledWidth = 0;
double scaledHeight = 0;
/* Set scaling to 0.5, i.e., set the size of the */
/* virtual sensor to 2x the size of the physical sensor */
errRes = PylonDeviceSetFloatFeature(hdev, "BslScalingFactor", 0.5);
CHECK(errRes);
/* Get the size of the virtual sensor */
errRes = PylonDeviceGetFloatFeature(hdev, "BslScaledSensorWidth", &scaledWidth);
CHECK(errRes);
errRes = PylonDeviceGetFloatFeature(hdev, "BslScaledSensorHeight", &scaledHeight);
CHECK(errRes);
/* Disable scaling */
errRes = PylonDeviceSetFloatFeature(hdev, "BslScalingFactor", 1.0);
CHECK(errRes);
# Set scaling to 0.5, i.e., set the size of the
# virtual sensor to 2x the size of the physical sensor
camera.BslScalingFactor.Value = 0.5
# Get the size of the virtual sensor
scaledWidth = camera.BslScaledSensorWidth.Value
scaledHeight = camera.BslScaledSensorHeight.Value
# Disable scaling
camera.BslScalingFactor.Value = 1.0

您也可以使用 pylon Viewer 輕鬆設定參數。