Camera Emulation#
可透過 `pylon API ` 和 `pylon Viewer` 存取相機模擬裝置。
總覽#
除了 GigE Vision 或USB3 Vision 等相機傳輸層之外,pylon 還提供了一種可建立簡易相機模擬裝置的傳輸層。這讓您無需實體相機即可開發應用程式。若您想開發多相機應用程式,但手邊沒有足夠的相機時,此功能同樣十分實用。
您可以建立最多 256 個攝影機模擬裝置。
除了模擬影像擷取及標準相機功能外,相機模擬裝置還提供實體相機所沒有的功能:
啟用相機模擬功能#
您可以在「pylon Viewer 」中、在「pylon API 」中,或兩者皆啟用相機模擬功能。
安裝攝影機模擬支援#
- 若您使用的是適用於Linux 的 pylon,相機模擬功能預設已安裝。
- 如果您正在使用 Pylon 來執行 `Windows `,並且是透過執行階段再發行套件安裝 Pylon 的話,相機模擬功能預設已安裝。
- 如果您正在使用 pylon 來執行Windows ,並且是透過pylon Software Suite 安裝程式安裝 pylon 的話:
- 若您在安裝過程中選擇了「相機使用者」或「開發者」設定檔,系統預設會安裝相機模擬功能。
- 如果您在安裝過程中選擇了「自訂」設定檔,則只有在您勾選了「相機模擬支援 」選項 的情況下,才會安裝相機模擬支援功能。若您尚未勾選該選項,請重新執行安裝程式並勾選該選項。
在pylon Viewer#
要在pylon Viewer 中啟用相機模擬功能:
- 請確認已安裝相機模擬功能。
- 在「pylon Viewer 」的「工具」選單中,按一下「選項」。
- 在「選項」對話方塊中,請按一下「相機模擬」。
- 在「相機模擬」頁面上,輸入所需的相機模擬裝置數量,然後按一下「確定」。
稍等片刻後,這些模擬裝置便會顯示在「裝置」窗格中。
您可以透過「pylon Viewer 」存取這些裝置。若您也想在「pylon API 」中存取這些裝置,請依照以下說明操作。
資訊
若將相機模擬裝置的數量設定為 0,則「相機模擬」節點將不會顯示在「裝置」窗格中。
在pylon API#
要在pylon API 中啟用相機模擬功能:
- 請確認已安裝相機模擬功能。
- 新增一個 系統環境變數 名為
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
- Resulting Acquisition Frame Rate
- Test Images
- 觸發式影像擷取
其他功能#
以下功能僅適用於相機模擬裝置,不適用於實體 Basler 相機。
顯示自訂Test Images#
除了顯示標準測試影像外,相機模擬功能還允許您顯示從磁碟載入的自訂測試影像。
資訊
- 在 Windows,可載入以下圖像檔案格式:BMP、JPG、PNG 及 TIF。
- 在 Linux,可載入以下圖像檔案格式:PNG 和 TIF。
要顯示自訂測試圖片:
- 將相機中的
TestImageSelector參數設為Off.
此設定將停用標準測試圖像。 - 將相機中的
ImageFileMode參數設為On.
這使得使用者能夠使用自訂測試圖像。 - 若您想顯示一個 單一 測試圖片,請在
ImageFilename參數中選擇性地指定 HTML 記錄檔 (*.html) 的路徑與檔名。
範例: c:\images\my-test-image.png -
若要顯示多張測試圖片:
- 請將所有待顯示的測試圖片放置於同一個目錄中。
該目錄不得包含任何子目錄。 - 請提供包含該檔案的目錄之完整路徑:
ImageFilename參數中選擇性地指定 HTML 記錄檔 (*.html) 的路徑與檔名。
範例: c:\images\
- 請將所有待顯示的測試圖片放置於同一個目錄中。
-
請拍攝至少一張照片,以顯示測試影像。若要將影像顯示於「pylon Viewer 」中,請點擊工具列上的單張或連拍按鈕。
疑難排解#
- 如果自訂測試圖像未顯示(即顯示的圖像完全為黑色),則表示 pylon 無法載入該檔案。請檢查在
ImageFilename參數。若您提供了目錄名稱,請確保該目錄中不包含任何子目錄。 - 如果自訂測試圖像以單色顯示,請切換至彩色像素格式(BGR/BGRA/RGB)。
- 如果自訂測試圖片未以全尺寸顯示,請調整 影像 ROI 參數 (
Width,Height,OffsetX以及OffsetY)。
若圖片尺寸大於 4096 x 4096:在設定Width進行明確的生命週期管理即呼叫Height參數,請確保該WidthMax進行明確的生命週期管理即呼叫HeightMax參數值已調整至正確的最大影像尺寸。
產生失敗的緩衝區#
「強制緩衝區失敗」功能可透過產生失敗的緩衝區,模擬相機連線異常的情況。此功能可應用於測試您的例外處理例程等情境。
要產生失敗的緩衝區:
- 開始影像擷取。
- 將相機中的
ForceFailedBufferCount將此參數設定為您要產生的失敗緩衝區數量。 - 執行
ForceFailedBuffer指令。
相機模擬裝置現在將產生損壞的影像。損壞影像的數量取決於ForceFailedBufferCount參數中選擇性地指定 HTML 記錄檔 (*.html) 的路徑與檔名。
外部連結#
範例程式碼#
// ** 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()
您也可以 use the pylon Viewer 來輕鬆設定參數。