相機模擬#
您可以透過 pylon API 和 pylon Viewer 存取相機模擬裝置。
概覽#
除了 GigE Vision 或 USB3 Vision 等相機傳輸層之外,pylon 還提供了一個可以建立簡單相機模擬裝置的傳輸層。這使您能夠在不需要實體相機的情況下開發應用程式。如果您想開發多相機應用程式但手頭沒有足夠的相機,這也非常有用。
您最多可以建立 256 個相機模擬裝置。
除了模擬影像擷取和 standard camera features 之外,相機模擬裝置還提供實體相機所沒有的功能:
- 您可以 display custom test images,例如用於最佳化您的影像處理演算法。
- 您可以 generate failed buffers,例如用於測試您的異常處理常式。
啟用 Camera Emulation#
您可以在 in the pylon Viewer、in the pylon API 或兩者中啟用相機模擬。
安裝 Camera Emulation 支援#
- 如果您使用的是適用於 Linux 的 pylon,則預設會安裝相機模擬支援。
- 如果您使用的是適用於 Windows 的 pylon 並且透過執行階段可轉發套件安裝了 pylon,則預設會安裝相機模擬支援。
- 如果您使用的是適用於 Windows 的 pylon 並且透過 pylon Software Suite 安裝程式安裝了 pylon:
- 如果您在安裝過程中選擇了 Camera User 或 Developer 設定檔,則預設會安裝相機模擬支援。
- 如果您在安裝過程中選擇了 Custom 設定檔,則只有在您選取了 Camera Emulation Support 選項時才會安裝相機模擬支援。如果您尚未這樣做,請再次執行安裝程式並選取該選項。
在 pylon Viewer 中啟用 Camera Emulation#
若要在 pylon Viewer 中啟用相機模擬:
- 請確保已 installed 相機模擬支援。
- 在 pylon Viewer 的 Tools 選單中,按一下 Options。
- 在 Options 對話方塊中,按一下 Camera Emulation。
- 在 Camera Emulation 頁面上,輸入所需的相機模擬裝置數量,然後按一下 OK。
稍等片刻後,模擬裝置將顯示在 Devices 窗格中。
您可以使用 pylon Viewer 存取它們。如果您還想在 pylon API 中存取這些裝置,請遵循 instructions below。
資訊
如果相機模擬裝置的數量設定為 0,則 Camera Emulation 節點將不會顯示在 Devices 窗格中。
在 pylon API 中啟用 Camera Emulation#
若要在 pylon API 中啟用相機模擬:
- 請確保已 installed 相機模擬支援。
- 新增一個 系統環境變數 命名為
PYLON_CAMEMU並將其值設為所需的模擬裝置數量。
範例:PYLON_CAMEMU=2
這將提供兩個模擬裝置。
可以使用 pylon API 來存取它們。如果您也想在 pylon Viewer 中存取這些裝置,請遵循 上述說明.
資訊
如果 PYLON_CAMEMU 若未設定或設為 0,將不會有可用的模擬裝置。
標準相機功能#
相機模擬裝置可以模擬以下標準相機功能:
- Acquisition Frame Rate
- Acquisition Status
- Device Information Parameters
- Exposure Mode
- Exposure Time
- Gain
- Image ROI
- Pixel Format
- 產生的 Acquisition Frame Rate
- Test Images
- 觸發式影像擷取
其他功能#
以下功能僅適用於相機模擬裝置,不適用於實體 Basler 相機。
顯示自訂 Test Images#
除了顯示標準的 Test Images 之外,相機模擬還允許您顯示從磁碟載入的自訂測試影像。
資訊
- 在 Windows 上,可以載入以下影像檔案格式:BMP、JPG、PNG 和 TIF。
- 在 Linux 上,可以載入以下影像檔案格式:PNG 和 TIF。
若要顯示自訂測試影像:
- 將
TestImageSelector參數設為Off.
這會停用標準測試影像的使用。 - 將
ImageFileMode參數設為On.
這會啟用自訂測試影像的使用。 - 如果您想要顯示 單一 測試影像,請在
ImageFilename參數的值。
範例: c:\images\my-test-image.png -
如果您想要顯示多張測試影像:
- 將所有要顯示的測試影像放置在單一目錄中。
該目錄不得包含任何子目錄。 - 請在
ImageFilename參數的值。
範例: c:\images\
- 將所有要顯示的測試影像放置在單一目錄中。
-
擷取至少一張影像以顯示測試影像。如果您想在 pylon Viewer 中顯示影像,請按一下工具列上的單張或連續拍攝按鈕。
故障排除#
- 如果未顯示自訂測試影像(即顯示的影像完全為黑色),則表示 pylon 無法載入該檔案。請檢查檔案名稱或提供的路徑位於
ImageFilename參數。如果您提供的是目錄名稱,請確保該目錄不包含任何子目錄。 - 如果自訂測試影像顯示為單色,請切換至彩色 pixel format (BGR/BGRA/RGB)。
- 如果自訂測試影像未以完整大小顯示,請調整 影像 ROI 參數(
Width,Height,OffsetX的狀態,以及OffsetY)。
如果影像大於 4096 x 4096:在設定Width和Height參數之前,請確保WidthMax和HeightMax參數值已調整至正確的最大影像大小。
產生失敗的緩衝區#
Force Failed Buffer 功能允許您透過產生失敗的緩衝區來模擬不良的相機連線。這對於測試您的例外處理常式等情況非常有用。
若要產生失敗的緩衝區:
- 開始影像擷取。
- 將
ForceFailedBufferCount參數設定為您想要產生的失敗緩衝區數量。 - 執行
ForceFailedBuffer命令。
相機模擬裝置現在將產生損壞的影像。損壞影像的數量取決於ForceFailedBufferCount參數的值。
外部連結#
範例程式碼#
// ** Custom Test Images **
// Disable standard test images
camera.TestImageSelector.SetValue(TestImageSelector_Off);
// Enable custom test images
camera.ImageFileMode.SetValue(ImageFileMode_On);
// Load custom test image from disk
camera.ImageFilename.SetValue("c:\\images\\image1.png");
// ** Force Failed Buffer **
// Set the number of failed buffers to generate to 40
camera.ForceFailedBufferCount.SetValue(40);
// Generate 40 failed buffers
camera.ForceFailedBuffer.Execute();
INodeMap& nodemap = camera.GetNodeMap();
// ** Custom Test Images **
// Disable standard test images
CEnumParameter(nodemap, "TestImageSelector").SetValue("Off");
// Enable custom test images
CEnumParameter(nodemap, "ImageFileMode").SetValue("On");
// Load custom test image from disk
CStringParameter(nodemap, "ImageFilename").SetValue("c:\\images\\image1.png");
// ** Force Failed Buffer **
// Set the number of failed buffers to generate to 40
CIntegerParameter(nodemap, "ForceFailedBufferCount").SetValue(40);
// Generate 40 failed buffers
CCommandParameter(nodemap, "ForceFailedBuffer").Execute();
// ** Custom Test Images **
// Disable standard test images
camera.Parameters[PLCamera.TestImageSelector].SetValue(PLCamera.TestImageSelector.Off);
// Enable custom test images
camera.Parameters[PLCamera.ImageFileMode].SetValue(PLCamera.ImageFileMode.On);
// Load custom test image from disk
camera.Parameters[PLCamera.ImageFilename].SetValue("c:\\images\\image1.png");
// ** Force Failed Buffer **
// Set the number of failed buffers to generate to 40
camera.Parameters[PLCamera.ForceFailedBufferCount].SetValue(40);
// Generate 40 failed buffers
camera.Parameters[PLCamera.ForceFailedBuffer].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 */
/* ** Custom Test Images ** */
/* Disable standard test images */
errRes = PylonDeviceFeatureFromString(hdev, "TestImageSelector", "Off");
CHECK(errRes);
/* Enable custom test images */
errRes = PylonDeviceFeatureFromString(hdev, "ImageFileMode", "On");
CHECK(errRes);
/* Load custom test image from disk */
errRes = PylonDeviceFeatureFromString(hdev, "ImageFilename", "c:\\images\\image1.png");
CHECK(errRes);
/* ** Force Failed Buffer ** */
/* Set the number of failed buffers to generate to 40 */
errRes = PylonDeviceSetIntegerFeature(hdev, "ForceFailedBufferCount", 40);
CHECK(errRes);
/* Generate 40 failed buffers */
errRes = PylonDeviceExecuteCommandFeature(hdev, "ForceFailedBuffer");
CHECK(errRes);
# ** Custom Test Images **
# Disable standard test images
camera.TestImageSelector.Value = "Off"
# Enable custom test images
camera.ImageFileMode.Value = "On"
# Load custom test image from disk
camera.ImageFilename.Value = "c:\\images\\image1.png"
# ** Force Failed Buffer **
# Set the number of failed buffers to generate to 40
camera.ForceFailedBufferCount.Value = 40
# Generate 40 failed buffers
camera.ForceFailedBuffer.Execute()
您也可以使用 pylon Viewer 來輕鬆設定參數。