觸發式影像擷取#
若無觸發,相機將自由運行,畫面可能會錯失相關時機。透過觸發,外部事件會觸發相機並在恰當的時刻擷取物件。
這可確保以下幾點:
- 影像與真實世界同步。
- 測量結果具備可重複性。
- 系統表現具備確定性。
可用作觸發源的外部事件範例:
- 移動物件到達特定位置
- 感測器偵測到零件
- 自動化系統中的 PLC 信號
- 照明脈衝或頻閃事件
此視覺化圖表總結了典型的工作流程:
觸發讓相機開始曝光。接著從感測器讀出資料、進行預處理,並傳輸至主機。最後,將其傳遞給應用程式。
典型應用案例#
在以下情況下請使用觸發採集:
- 時間至關重要:影像必須準確對應至實體事件,例如用於高速分選。
- 必須精確凍結動作:您希望在相同位置擷取高速移動的物件,例如用於輸送帶檢測。
- 由外部系統控制流程:PLC、感測器、編碼器或其他硬體會定義何時進行擷取,例如在機器人應用中。
- 需要具備確定性的行為:每個觸發都會產生剛好一個具有明確時序的畫面,例如用於測量系統。
軟體觸發#
軟體觸發允許您透過軟體呼叫來開始曝光,而不是透過外部硬體事件。如果來源不是硬體事件而是運算系統的狀態變更,這會非常有用。這通常與硬體觸發一樣精確,並在許多情況下已足夠。主要的優點在於,它比將運算系統的輸出連接到相機要來得簡單。
camera.TriggerSelector.Value = "FrameStart"
camera.TriggerMode.Value = "On"
camera.TriggerSource .Value = "Software"
camera.ExecuteSoftwareTrigger()
範例:週期性軟體觸發 (1 Hz)#
以下範例使用軟體觸發來每秒開始一次影像曝光。
import time
from pypylon import pylon
def process(image):
h, w = image.shape[:2]
center_pixel = image[h // 2, w // 2]
print("Center pixel:", center_pixel)
with pylon.InstantCamera(pylon.FirstFound) as camera:
# Open is necessary before accessing the parameters.
camera.Open()
# Enable trigger mode.
camera.TriggerSelector.Value = "FrameStart"
camera.TriggerMode.Value = "On"
camera.TriggerSource.Value = "Software"
camera.StartGrabbing(pylon.GrabStrategy_OneByOne)
while camera.IsGrabbing():
camera.ExecuteSoftwareTrigger()
with camera.RetrieveResult(2000) as grab_result:
if grab_result.GrabSucceeded():
image = grab_result.Array
process(image)
else:
print("Grab failed:", grab_result.ErrorDescription)
time.sleep(1.0)
硬體觸發#
如果軟體觸發不夠精確以滿足您的使用需求,或者硬體信號已經可用,則使用硬體觸發是最佳選擇。
在這種情況下,根據相機型號的不同,會有一個或多個可用於充當觸發輸入的輸入端。可以使用上升緣或下降緣來觸發諸如相機曝光開始等事件。
camera.TriggerSource.Value = "Line1"
camera.TriggerSelector.Value = "FrameStart"
camera.TriggerActivation.Value = "RisingEdge"
範例:硬體觸發採集#
在以下範例中,會使用找到的第一台相機上的輸入線路 1 來啟動曝光並輸出中心像素。
from pypylon import pylon
def process(image):
height, width = image.shape[:2]
center_pixel = image[height // 2, width // 2]
print("Center pixel:", center_pixel)
with pylon.InstantCamera(pylon.FirstFound) as camera:
# Open is necessary before accessing the parameters.
camera.Open()
# Configure hardware trigger
camera.TriggerSelector.Value = "FrameStart"
camera.TriggerMode.Value = "On"
camera.TriggerActivation.Value = "RisingEdge"
camera.TriggerSource.Value = "Line1"
camera.StartGrabbing(pylon.GrabStrategy_OneByOne)
while camera.IsGrabbing():
with camera.RetrieveResult(5000) as grab_result:
if grab_result.GrabSucceeded():
image = grab_result.Array
process(image)
else:
print("Grab failed:", grab_result.ErrorDescription)