跳转到内容
STAGING SERVER
DEVELOPMENT SERVER

触发图像采集#

当图像采集需要在特定时间点进行而非连续进行时,将使用触发采集。

如果没有触发,相机将自由运行,图像可能会错过相关时刻。通过触发,外部事件会触发相机并在恰当的时刻捕获物体。

这可确保以下几点:

  • 图像与真实世界保持同步。
  • 测量结果具有可重复性。
  • 系统表现出确定性。

可用作触发器的外部事件示例:

  • 移动的物体到达特定位置
  • 传感器检测到零件
  • 自动化系统中的 PLC 信号
  • 照明脉冲或选通事件

此可视化图表总结了典型的工作流程:

Trigger → Exposure → Readout → Transfer → Application

触发使相机开始曝光。系统从传感器读出此数据,进行预处理并传输至主机。最后,将其传递给应用程序。

典型用例#

在以下情况下请使用触发采集:

  • 时序至关重要:图像必须准确对应物理事件,例如用于高速分拣。
  • 必须精确冻结运动:您希望在相同位置捕获快速移动的物体,例如用于传送带检测。
  • 外部系统控制流程: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)