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

Defect Pixel Correction#

Defect Pixel Correction camera feature 可讓您將感光元件中各個像素靈敏度差異的影響降到最低。

在擷取的影像中,即使使用均勻的光源,某些像素看起來也可能比其餘像素明顯更亮或更暗。此問題是由個別像素的靈敏度差異所引起,而這又是製造公差所造成的。

使用此功能#

此功能的實作方式會因相機而異:

ace 2 R/X、boost R 和 dart M 相機#

Basler ace 2 R、ace 2 X、boost R 和 dart M 相機支援 static defect pixel correction。此校正是以儲存在相機上且包含缺陷像素座標清單的檔案為基礎。

"Static" 表示校正過程一律使用相同的指定缺陷像素座標。在影像擷取期間,會根據相鄰像素的強度值來取代精確這些像素的強度值。

下列 defect pixel correction 檔案可以儲存在相機上:

  • Factory file: 包含在相機生產過程中偵測到的缺陷像素座標。
  • User file:包含使用者定義的座標。您可以將此檔案上傳至相機。這可讓您定義隨著時間可能出現的新缺陷像素。

資訊

Basler ace 2 X 相機也支援 dynamic pixel defect correction。如需詳細資訊,請參閱 Pixel Correction Beyond。

使用 pylon Viewer 校正缺陷像素#

→ 請參閱 Static Defect Pixel Correction (pylon Viewer)。

使用 pylon API 校正缺陷像素#

資訊

Basler 建議使用 pylon Viewer 執行 defect pixel correction。

只有在您想要於自己的應用程式中實作 defect pixel correction 時,才使用 pylon API。

設定 Static Defect Pixel Correction Mode#

若要設定 static defect pixel correction mode,請將 BslStaticDefectPixelCorrectionMode 參數設為下列其中一個值:

  • Factory (預設):Static defect pixel correction 是以儲存在 factory 校正檔案中的缺陷像素為基礎。
  • User:Static defect pixel correction 是以儲存在 user 校正檔案中的缺陷像素為基礎。
    請注意,透過 pylon API 設定此模式時, 僅會 使用使用者定義的像素。透過 User incl. Factory 設定 pylon Viewer校正模式時,除了儲存在 factory file 中的像素外,還會使用使用者定義的像素。
  • Off:相機 不會 執行靜態壞點校正。
上傳 User Defect Pixel Correction File#

在上傳 user defect pixel correction file 之前,請確保該檔案符合以下檔案格式:

檔案必須以包含四個值為 0 之位元組的 4 位元組標頭開頭。標頭後面必須包含壞點條目(最多可指定 4096 個壞點)。每個條目由 32 位元組成,順序如下:14 位元 y 坐標、14 位元 x 坐標、4 位元類型

範例:坐標 x = 1 且 y = 2 的壞點條目

Bit   |31          18| |17           4| |3  0|
Value |00000000000010| |00000000000001| |0000|
      | y = 2        | | X = 1        | |type|

若要使用 pylon Viewer 上傳 user defect pixel correction file:

  1. 在 pylon Viewer 的 Camera 功能表中,按一下 File Access。
  2. 在 Camera File 下拉式方塊中,選取 User Defect Pixel Correction。
    如果沒有 User Defect Pixel Correction 項目,表示您的相機不支援上傳校正檔案。
  3. 按一下 Upload 並瀏覽至您要上傳的檔案。
  4. 按一下 Open。

若要在上傳後套用 user defect pixel correction file,請確保 BslStaticDefectPixelCorrectionMode 參數已設定為 User 並執行 BslStaticDefectPixelCorrectionReload 命令。

下載壞點校正檔案#

下載壞點校正檔案(例如原廠校正檔案)在您想要將自行測量的壞點新增至已下載的檔案時可能會很有用。您可以將完整的壞點條目清單儲存到新的使用者校正檔案中。

若要使用 pylon Viewer 下載壞點校正檔案:

  1. 在 pylon Viewer 的 Camera 功能表中,按一下 File Access。
  2. 在 Camera File 下拉式方塊中,根據您要下載的檔案選取 Static Factory Defect Pixel Correction 或 Static User Defect Pixel Correction。
    如果沒有適當的項目,表示您的相機不支援下載檔案。
  3. 按一下 Download,瀏覽至您要儲存檔案的目錄,然後輸入所需的檔案名稱。
  4. 按一下 Open。
靜態壞點校正檔案狀態#

影像 StaticDefectPixelCorrectionFileStatus 參數可接受下列值:

  • FileStatusUnknown:壞點校正檔案狀態未知。擷取影像以變更檔案狀態。
  • FileOk:壞點校正檔案有效。
  • FileNotFound:找不到壞點校正檔案。它從未上傳或已被刪除。
  • FileEmpty:壞點校正檔案沒有任何條目。檔案標頭有效,但檔案未包含任何壞點。壞點校正程序已中止。
  • InvalidHeader: 缺陷像素校正檔案標頭無效。檔案必須包含 4 位元組的檔案標頭。
  • InvalidSize: 缺陷像素校正檔案大小無效。缺陷像素的最大數量不得超過 4096。
  • InvalidSorting: 缺陷像素校正檔案中的項目排序無效。缺陷像素校正程序已中止。
  • InvalidFileEntry: 缺陷像素校正檔案中至少有一個項目的大小無效。缺陷像素校正程序已中止。
  • InvalidClustering: 發現無效的叢集。同一列中三個或更多相鄰的像素會被視為無效叢集。位於其他缺陷像素之間的任何缺陷像素都無法被校正。

缺陷像素校正檔案最多可以包含一定數量的缺陷像素。若要取得此數量,請取得以下項目的值: BslStaticDefectPixelCorrectionMaxDefects 參數的值。

boost V 相機#

Basler boost V 相機支援 Static Defect Pixel Correction。此校正基於儲存在相機上且包含缺陷像素座標清單的檔案。

"Static" 表示校正過程一律使用相同的指定缺陷像素座標。在影像擷取期間,會根據相鄰像素的強度值來取代精確這些像素的強度值。

執行 Defect Pixel Correction#

資訊

pylon Viewer 內建的 Static Defect Pixel Correction 功能不支援 boost V 相機。

使用 pylon Viewer 的功能樹狀結構或 pylon API 在 boost V 相機上執行缺陷像素校正。

若要在 boost V 相機上執行缺陷像素校正:

  1. 將 BslStaticDefectPixelCorrectionMode 參數設為所需的校正模式:

    • Factory: 僅校正座標儲存在原廠檔案中的缺陷像素。原廠檔案是在相機生產期間產生的,且無法更改。
    • User: 您可以指定自訂的缺陷像素座標。
    • Off:相機 不會 執行靜態壞點校正。
  2. 如果您選擇了 User:

    1. 尋找影像中的像素錯誤,並記下缺陷像素的 x 和 y 座標。
    2. 將 BslStaticDefectPixelCorrectionYCoordinate 參數設為 y 第一個缺陷像素的座標。
    3. 將 BslStaticDefectPixelCorrectionXSelector 參數設為 X0.
    4. 將 BslStaticDefectPixelCorrectionXCoordinate 參數設為 x 第一個缺陷像素的座標。
    5. 如果還有另一個具有相同 y 座標但 x 座標不同的缺陷像素,請將 BslStaticDefectPixelCorrectionXSelector 參數設為下一個項目,例如 X1,並輸入下一個 x 座標。
    6. 對所有其他像素錯誤重複步驟 b 到 e。
    7. 執行 BslStaticDefectPixelCorrectionSave 指令以將變更儲存至 flash memory。

資訊

  • 您可以使用 BslStaticDefectPixelCorrectionCount 參數以檢查目前正在校正多少影像像素。
  • 您可以將 BslStaticDefectPixelCorrectionTestMode 參數設為 On 設為將所有已校正的像素設為完全白色。這有助於尋找圖像中正在進行校正的像素。

移除缺陷像素坐標#

無法移除原廠檔案中的像素座標。

不過,您可以移除自訂缺陷像素座標,也就是在「User」校正模式中輸入的座標(請參閱上方)。若要這樣做:

  • 如果您想移除單個自訂缺陷像素座標:

    1. 將 BslStaticDefectPixelCorrectionYCoordinate 參數設為 y 缺陷像素的座標。
    2. 將 BslStaticDefectPixelCorrectionXSelector 參數設為保留缺陷像素 x 座標的項目,例如 X0.
    3. 將 BslStaticDefectPixelCorrectionXCoordinate 參數設為 0xFFFF。
    4. 執行 BslStaticDefectPixelCorrectionSave 指令以將變更儲存至 flash memory。
  • 如果您想移除所有自訂缺陷像素座標:

    1. 執行 BslStaticDefectPixelCorrectionClearAll 指令。這會將所有 BslStaticDefectPixelCorrectionXCoordinate 參數值設為 0xFFFF。
    2. 執行 BslStaticDefectPixelCorrectionSave 指令以將變更儲存至 flash memory。

dart 與 pulse 相機#

Basler dart and pulse cameras 可以執行兩種類型的像素校正:

  • 靜態像素校正用於校正強度值明顯低於相鄰像素(包括完全黑色像素)的像素。
  • 動態像素校正用於校正強度值明顯高於相鄰像素(包括完全白色像素)的像素。內部閾值定義了何時將像素偵測為「熱像素」。「動態」表示缺陷像素校正是針對每張擷取的影像分別計算的。

設定 Defect Pixel Correction Mode#

若要設定缺陷像素校正模式,請將 BslDefectPixelCorrectionMode 參數設為下列其中一個值:

  • On (預設):相機執行 靜態和動態 像素校正。
  • StaticOnly:相機僅執行 靜態 像素校正。
  • Off:相機 不會 執行像素校正。

範例程式碼#

ace 2 R/X、boost R 和 dart M 相機#
// Set static user defect pixel correction
camera.BslStaticDefectPixelCorrectionMode.SetValue(BslStaticDefectPixelCorrectionMode_User);
// Reload static defect pixel correction file
camera.BslStaticDefectPixelCorrectionReload.Execute();
INodeMap& nodemap = camera.GetNodeMap();
// Set static user defect pixel correction
CEnumParameter(nodemap, "BslStaticDefectPixelCorrectionMode").SetValue("User");
// Reload static defect pixel correction file
CCommandParameter(nodemap, "BslStaticDefectPixelCorrectionReload").Execute();
// Set static user defect pixel correction
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionMode].SetValue(PLCamera.BslStaticDefectPixelCorrectionMode.User);
// Reload static defect pixel correction file
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionReload].Execute();
/* 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 */
/* Set static user defect pixel correction */
errRes = PylonDeviceFeatureFromString(hdev, "BslStaticDefectPixelCorrectionMode", "User");
CHECK(errRes);
/* Reload static defect pixel correction file */
errRes = PylonDeviceExecuteCommandFeature(hdev, "BslStaticDefectPixelCorrectionReload");
CHECK(errRes);
# Set static user defect pixel correction
camera.BslStaticDefectPixelCorrectionMode.Value = "User"
# Reload static defect pixel correction file
camera.BslStaticDefectPixelCorrectionReload.Execute()
boost V 相機#
// Set the defect pixel correction mode to User
camera.BslStaticDefectPixelCorrectionMode.SetValue(BslStaticDefectPixelCorrectionMode_User);
// Assume there are two defect pixels at coordinates (120,430) and (182,430)
// Set the y coordinate to 430
camera.BslStaticDefectPixelCorrectionYCoordinate.SetValue(430);
// Select entry X0 and assign the first x coordinate
camera.BslStaticDefectPixelCorrectionXSelector.SetValue(BslStaticDefectPixelCorrectionXSelector_X0);
camera.BslStaticDefectPixelCorrectionXCoordinate.SetValue(120);
// Select entry X1 and assign the second x coordinate, which is in the same line
camera.BslStaticDefectPixelCorrectionXSelector.SetValue(BslStaticDefectPixelCorrectionXSelector_X1);
camera.BslStaticDefectPixelCorrectionXCoordinate.SetValue(182);
// Save changes to flash memory
camera.BslStaticDefectPixelCorrectionSave.Execute();
INodeMap& nodemap = camera.GetNodeMap();
// Set the defect pixel correction mode to User
CEnumParameter(nodemap, "BslStaticDefectPixelCorrectionMode").SetValue("User");
// Assume there are two defect pixels at coordinates (120,430) and (182,430)
// Set the y coordinate to 430
CIntegerParameter(nodemap, "BslStaticDefectPixelCorrectionYCoordinate").SetValue(430);
// Select entry X0 and assign the first x coordinate
CEnumParameter(nodemap, "BslStaticDefectPixelCorrectionXSelector").SetValue("X0");
CIntegerParameter(nodemap, "BslStaticDefectPixelCorrectionXCoordinate").SetValue(120);
// Select entry X1 and assign the second x coordinate, which is in the same line
CEnumParameter(nodemap, "BslStaticDefectPixelCorrectionXSelector").SetValue("X1");
CIntegerParameter(nodemap, "BslStaticDefectPixelCorrectionXCoordinate").SetValue(182);
// Save changes to flash memory
CCommandParameter(nodemap, "BslStaticDefectPixelCorrectionSave").Execute();
// Set the defect pixel correction mode to User
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionMode].SetValue(PLCamera.BslStaticDefectPixelCorrectionMode.User);
// Assume there are two defect pixels at coordinates (120,430) and (182,430)
// Set the y coordinate to 430
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionYCoordinate].SetValue(430);
// Select entry X0 and assign the first x coordinate
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionXSelector].SetValue(PLCamera.BslStaticDefectPixelCorrectionXSelector.X0);
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionXCoordinate].SetValue(120);
// Select entry X1 and assign the second x coordinate, which is in the same line
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionXSelector].SetValue(PLCamera.BslStaticDefectPixelCorrectionXSelector.X1);
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionXCoordinate].SetValue(182);
// Save changes to flash memory
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionSave].Execute();
/* 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 */
/* Set the defect pixel correction mode to User */
errRes = PylonDeviceFeatureFromString(hdev, "BslStaticDefectPixelCorrectionMode", "User");
CHECK(errRes);
/* Assume there are two defect pixels at coordinates (120,430) and (182,430) */
/* Set the y coordinate to 430 */
errRes = PylonDeviceSetIntegerFeature(hdev, "BslStaticDefectPixelCorrectionYCoordinate", 430);
CHECK(errRes);
/* Select entry X0 and assign the first x coordinate */
errRes = PylonDeviceFeatureFromString(hdev, "BslStaticDefectPixelCorrectionXSelector", "X0");
CHECK(errRes);
errRes = PylonDeviceSetIntegerFeature(hdev, "BslStaticDefectPixelCorrectionXCoordinate", 120);
CHECK(errRes);
/* Select entry X1 and assign the second x coordinate, which is in the same line */
errRes = PylonDeviceFeatureFromString(hdev, "BslStaticDefectPixelCorrectionXSelector", "X1");
CHECK(errRes);
errRes = PylonDeviceSetIntegerFeature(hdev, "BslStaticDefectPixelCorrectionXCoordinate", 182);
CHECK(errRes);
/* Save changes to flash memory */
errRes = PylonDeviceExecuteCommandFeature(hdev, "BslStaticDefectPixelCorrectionSave");
CHECK(errRes);
# Set the defect pixel correction mode to User
camera.BslStaticDefectPixelCorrectionMode.Value = "User"
# Assume there are two defect pixels at coordinates (120,430) and (182,430)
# Set the y coordinate to 430
camera.BslStaticDefectPixelCorrectionYCoordinate.Value = 430
# Select entry X0 and assign the first x coordinate
camera.BslStaticDefectPixelCorrectionXSelector.Value = "X0"
camera.BslStaticDefectPixelCorrectionXCoordinate.Value = 120
# Select entry X1 and assign the second x coordinate, which is in the same line
camera.BslStaticDefectPixelCorrectionXSelector.Value = "X1"
camera.BslStaticDefectPixelCorrectionXCoordinate.Value = 182
# Save changes to flash memory
camera.BslStaticDefectPixelCorrectionSave.Execute()
dart 與 pulse 相機#
// Disable defect pixel correction
camera.DefectPixelCorrectionMode.SetValue(DefectPixelCorrectionMode_Off);
INodeMap& nodemap = camera.GetNodeMap();
// Disable defect pixel correction
CEnumParameter(nodemap, "DefectPixelCorrectionMode").SetValue("Off");
// Disable defect pixel correction
camera.Parameters[PLCamera.DefectPixelCorrectionMode].SetValue(PLCamera.DefectPixelCorrectionMode.Off);
/* 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 */
/* Disable defect pixel correction */
errRes = PylonDeviceFeatureFromString(hdev, "DefectPixelCorrectionMode", "Off");
CHECK(errRes);
# Disable defect pixel correction
camera.DefectPixelCorrectionMode.Value = "Off"

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