VisionPro文档 -- 在单个作业里的多相机采集
目录
VisionPro作业旨在处理来自单个图像源(相机或图像文件)的图像。每次作业运行时,图像源都会提供一个图像,该作业的工具会处理该图像并提供一个整体结果。对于许多常见的应用程序,例如从几个不同的视图检查零件,让一个作业同时处理来自多个图像源的多个图像是有意义的。这些多个图像源可以分别与单独的相机关联,也可以共享一个相机(通常使用不同的基于硬件的兴趣区域)。本主题显示如何使用VisionPro作业支持此类应用程序。
注意:本主题中描述的功能是VisionPro 6.0版引入的;此功能与VisionPro版本无关。早期版本不支持此功能。另外,仅在需要在单个作业中处理多台摄像机的图像时,才应使用本主题中描述的技术;对于单镜头应用程序,请使用作业的图像源提供图像。
VisionPro jobs are designed to process images from a single image source, either a camera or an image file. Each time the job runs, the image source provides a single image, the job's tools process the image and provide a single overall result. For a number of common applications, such as inspecting a part from several different views, it makes sense to have a single job process multiple images from multiple image sources at the same time. These multiple images sources can each be associated with separate cameras, or they can share a single camera (typically using different hardware-based regions of interest). This topic shows how to support this type of application using VisionPro jobs.
Note: The functionality described in this topic was introduced with VisionPro version 6.0; it is not supported in earlier versions. Also, you should only use the techniques described in this topic if you need to process images from multiple cameras in a single job; for single-camera applications, use the job's image source to provide images.
重要说明
Important Limitations
本小节介绍如何在VisionPro作业中使用两个或多个嵌入式CogAcqFifo工具,而不是使用作业的内置图像源获取图像。 作业的图像源有助于管理图像采集的重要方面。 如果使用本节中介绍的技术,则必须牢记图像源和嵌入式CogAcqFifo工具之间的以下列出的主要区别。
This section describes how to use two or more embedded CogAcqFifo tools inside a VisionPro job instead of using the job's built-in image source to acquire images. The job's Image Source helps to manage important aspects of image acquisition. If you use the techniques describe in this section, you must keep the following key differences between the Image Source and an embedded CogAcqFifo tool in mind:
图像源管理队列大小和溢出选项
Image Source Manages Queue Size and Overflow Options
禁用图像源时,您将负责管理所获取图像的队列并确定如何处理队列溢出。 您在“作业属性”和“作业管理器属性”对话框中指定的队列选项将被忽略。
When you disable the Image Source, you are responsible for managing the queue of acquired images and determining how to handle queue overflow. The queue options that you specify in the Job Properties and Job Manager Properties dialog boxes are ignored.
触发器的启用和禁用
Trigger Enable and Disable
禁用图像源后,您将需要负责为每个嵌入式CogAcqFifo工具启用和禁用触发器,如管理CogAcqFifo触发部分中所述。 未能仔细管理CogAcqFifo触发会导致各种应用程序问题,包括应用程序挂起以及图像丢失或不正确。
When you disable the Image Source, you are responsible for enabling and disabling triggers for each embedded CogAcqFifo tool, as described in the section Managing CogAcqFifo Triggering. Failing to carefully manage CogAcqFifo triggering can cause a variety of application problems, including application hangs and lost or incorrect images.
管理硬件触发器
Managing Hardware Triggers
当禁用图像源并使用自动触发时,您将需要负责管理硬件触发,如“硬件触发”一节中所述。
When you disable the Image Source, and you are using automatic triggering, you are responsible for managing hardware triggers, as described in the section Hardware Triggers.
多相机作业的基本设置
Multi-Camera Job Basics
要配置多摄像机VisionPro作业,请按照以下步骤操作:
1. 在“配置作业属性”对话框中,通过取消选中“从图像来源种获取图像”复选框来禁用图像源。
In the Job Properties dialog box, disable the Image Source by unchecking the Acquire Images from Image Source check box.
2. 打开“工具箱”窗口,并为应用程序正在使用的每个摄像头添加一个CogAcqFifo工具。
Open the Toolbox window and add a CogAcqFifo tool for each camera that your application is using.
3. 依次打开每个CogAcqFifo工具,然后选择并配置该工具的摄像头。
Open each CogAcqFifo tool in turn and select and configure the camera for that tool.
4. 创建并配置您的应用程序所需的视觉和图像处理工具。 通常,您将为每个摄像机使用单独的工具,然后使用数据分析或结果分析工具合并工具结果以计算作业的总体结果。
Create and configure the vision and image processing tools required for your application. Typically, you will use separate tools for each camera, then combine tool results using a Data Analysis or Results Analysis tool to compute an overall result for the job.
注意:根据应用程序的复杂性,将每个摄像机的视觉工具封装在一个嵌套工具组中可能会更简单。
Note: Depending on the complexity of your application, it may be simpler to encapsulate each cameras' vision tools in a nested tool group.
管理CogAcqFifo触发
Managing CogAcqFifo Triggering
当您使用本主题中描述的技术在单个作业中实现多摄像机采集时,您的应用程序必须了解并显式管理与嵌入式CogAcqFifo工具关联的触发行为。 当您使用作业的图像源进行单摄像机采集时,作业将管理与触发关联的详细信息。 具体要求取决于您使用的触发模型。 本节将讨论每种模型。
注意:本节假定作业使用的所有摄像机都使用相同的触发器模型。
When you use the techniques described in this topic to implement multi-camera acquisition in a single job, your application must understand and explicitly manage the trigger behavior associated with the embedded CogAcqFifo tools. When you use the Job's Image Source for single-camera acquisition, the Job manages the details associated with triggering. The specific requirements depend on which triggering model you are using. Each model is discussed in this section.
Note: This section presumes that all the cameras used by the job are using the same trigger model.
手动(软件)触发
Manual (Software) Triggering
如果将CogAcqFifo工具配置为手动(软件)触发,则每个CogAcqFifo工具在运行时都会从其相机获取单个图像。 由于CogAcqFifo工具是按顺序运行的,因此可以在不同的时间获取图像,两次获取之间的最大间隔取决于每次获取所花费的时间。
If the CogAcqFifo tools are configured for manual (software) triggering, then each CogAcqFifo tool acquires a single image from its camera when it is run. Since the CogAcqFifo tools are run sequentially, the images are acquired at different times, with the maximum interval between acquisitions determined by how long each acquisition takes.
自动(硬件)触发
Automatic (Hardware) Triggering
如果将CogAcqFifo工具配置为自动触发,则每当相机收到硬件触发信号时,每个CogAcqFifo都会获取图像并排队。 只要CogAcqFifo的TriggerEnabled属性为True,无论作业是否在运行,都会进行此图像获取和排队。
如果作业在触发摄像机之前或之后运行,则可以使用自动触发。 在这两种情况下,图像都将同时获取并排队。 下图显示了在作业运行之前触发摄像机的情况下自动触发的工作方式:
If the CogAcqFifo tools are configured for automatic triggering, then each CogAcqFifo will acquire and queue an image whenever a hardware trigger is received by the camera. This image acquisition and queuing happens whether the job is running or not, as long as the CogAcqFifo's TriggerEnabled property is True.
You can use automatic triggering in cases where the job runs before or after the cameras are triggered. In both cases, the images will be acquired and queued simultaneously. The following figure shows how automatic triggering works in the case where the cameras are triggered before the job is run:
尽管CogAcqFifo工具按顺序运行,但是在接收到触发器时,图像会被获取并排队。 (不要求多个摄像机共享一个触发源;这些摄像机可以独立触发。)
如果作业在收到触发器之前运行,则作业将在第一个CogAcqFifo工具处阻止(停止),因为队列中没有可用的图像。 作业将一直阻塞,直到达到为该工具指定的超时时间为止,或者直到有可用的图像为止。 接收到触发信号后,所有三个CogAcqFifo的摄像头都会同时获取图像并排队。 图像可用后,作业将立即解除阻止,三个CogAcqFifo工具将按顺序运行,从而删除三个排队的图像,如下图所示:
Although the CogAcqFifo tools run sequentially, the images are acquired and queued when the trigger is received. (It is not a requirement that the multiple cameras share a single trigger source; the cameras may be triggered independently.)
If the job runs before the trigger is received, then the job blocks (stops) at the first CogAcqFifo tool, since there is no image available in the queue. The job will block until the timeout specified for that tool is reached, or until an image becomes available. When the trigger is received, all three CogAcqFifo's cameras acquire and queue their images simultaneously. As soon as the image becomes available, the job unblocks, the three CogAcqFifo tools run in sequence, removing the three queued images, as shown in the following figure:
注意:如本节所述,当您将CogAcqFifo工具嵌入到作业中时,VisionPro作业管理器不会为您管理CogAcqFifo工具的采集属性。 如果您保留包含配置用于自动(硬件)触发的CogAcqFifo工具且其TriggerEnabled属性为true的作业,则该工具将在取消触发后立即获取图像(如果已接收到触发器)。 另外,如果您运行包含CogAcqFifo工具的作业,则该作业将阻塞等待该CogAcqFifo工具完成其采集的时间,直到为该工具指定的超时时间。 如果为自动(硬件)触发器配置的工具指定了无限超时,则作业将阻塞,直到该工具收到触发器。
Note: When you embed a CogAcqFifo tool in a job as described in this section, the VisionPro Job Manager does not manage the acquisition properties of the CogAcqFifo tool for you. If you persist a job that contains a CogAcqFifo tool configured for automatic (hardware) triggering and its TriggerEnabled property is true, that tool will acquire images as soon as it is depersisted, if triggers are received. Also, if you run a job that contains a CogAcqFifo tool, the job will block waiting for that CogAcqFifo tool to complete its acquisition for as long as the timeout specified for that tool. If a tool configured for automatic (hardware) triggers specifies an unlimited timeout, the job will block until that tool receives a trigger.
*运行触发和半自动触发
Free-Running Triggering and Semi-Automatic Triggering
通常,*运行触发模式和半自动触发模式不适用于多摄像机采集作业,并且康耐视不建议使用它们。
如果将CogAcqFifo工具配置为*运行触发,则启用触发器后,每个CogAcqFifo工具的图像队列将被图像填充,并且每次运行作业时,将从每个CogAcqFifo获取图像。 但是,由于没有使摄像机之间的采集同步的机制,因此不会同时采集三个图像。
如果将CogAcqFifo工具配置为半自动触发,则每个CogAcqFifo将忽略触发器,直到运行该工具为止,然后在接收到下一个触发器时它将获取图像。 由于作业中的CogAcqFifo工具是按顺序运行的,因此将按顺序获取图像,并且图像间的延迟至少与手动(软件)触发的情况一样多。
In general, these trigger modes are not appropriate for multi-camera acquisition jobs and Cognex does not recommend their use.
If the CogAcqFifo tools are configured for free-running triggering, each CogAcqFifo tool's image queue will be filled with images as soon as triggers are enabled, and each time the job runs, an image will be obtained from each CogAcqFifo. There is no mechanism to synchronize the acquisition between the cameras, however, so the three images will not have been acquired simultaneously.
If the CogAcqFifo tools are configured for semi-automatic triggering, then each CogAcqFifo will ignore triggers until the tool is run, then it will acquire an image when the next trigger is received. Since the CogAcqFifo tools in a job are run sequentially, the images will be acquired sequentially, with at least as much inter-image latency as would be the case for manual (software) triggering.
解决多机位作业的常见问题
Solving Common Problems with Multi-Camera Jobs
本节介绍使用本节介绍的技术时可能遇到的一些常见问题。
This section describes some common issues that you may experience when using the techniques described in this section.
采集到错误或乱序图像
Wrong or Out-of-Sequence Images Acquired
作业运行时,每个CogAcqFifo工具都将获取与该工具关联的采集FIFO中可用的最旧图像。 如果自从取消作业以来相机已收到多个触发器,则多个图像已经排队。
在大多数情况下,您应在作业运行前刷新与每个CogAcqFifo工具关联的采集FIFO。 这样,您可以确保FIFO包含与最新硬件触发器关联的图像。 有两种刷新FIFO的方法。
- 打开CogAcqFifo工具编辑控件,单击“触发和选通”选项卡,然后单击“刷新FIFO”。
- 使用作业脚本以编程方式刷新FIFO。 下面的代码显示了如何设置事件处理程序,该事件处理程序在脚本运行时刷新作业的嵌入式CogAcqFifo工具的所有获取队列。 (您可以通过在“配置作业属性”对话框中单击“编辑作业脚本”来访问作业脚本编辑器。)
注意:您必须在脚本中添加对Cognex.VisionPro.ToolGroup的引用。
When the job runs, each CogAcqFifo tool will acquire the oldest image available in the acquisition FIFO associated with the tool. If the camera has received multiple triggers since the job was depersisted, multiple images will already be queued.
In most cases, you should flush the acquisition FIFOs associated with each CogAcqFifo tool before the job runs. This way, you can ensure that the FIFOs contain the images associated with the most recent hardware trigger. There are two ways to flush the FIFOs.
Open the CogAcqFifo tool edit control, click on the Trigger and Strobe tab, and click Flush FIFO.
Flush the FIFOs programmatically using the Job Script. The code below shows how to set up an event handler that flushes all of the acquisition queues for a job's embedded CogAcqFifo tools when the script runs. (You access the Job Script editor by clicking Edit Job Script in the Configure Job Properties dialog box.)
Note: You must add a reference to Cognex.VisionPro.ToolGroup to the script.
#region "When the Script is Initialized"
//Perform any initialization required by your script here.
public override void Initialize(CogJob jobParam)
{
//DO NOT REMOVE - Call the base class implementation first - DO NOT REMOVE
base.Initialize(jobParam);
// Add event handler to job start event
jobParam.Running += new CogJob.CogJobRunningEventHandler(FlushFIFOs);
}
#endregion
#region Event Handlers
public void FlushFIFOs(Object o, CogJobActionEventArgs e)
{
CogJob job = (CogJob) o;
CogToolGroup tg = job.VisionTool as CogToolGroup;
// Flush each tool's FIFO
CogAcqFifoTool caft = tg.Tools["CogAcqFifoTool1"] as CogAcqFifoTool;
caft.Operator.Flush();
caft = tg.Tools["CogAcqFifoTool2"] as CogAcqFifoTool;
caft.Operator.Flush();
caft = tg.Tools["CogAcqFifoTool3"] as CogAcqFifoTool;
caft.Operator.Flush();
}
#endregion
作业未运行时获取图像
Images are Acquired when Job is Not Running
一旦实例化或取消的作业包含配置为自动(硬件)触发的CogAcqFifo工具且其TriggerEnabled属性为true的作业,即使未运行该作业,该工具也将获取图像。
您可以通过将所有持久性作业的TriggerEnabled属性设置为false来防止发生这种情况。
As soon as you instantiate or depersist a job that contains a CogAcqFifo tool configured for automatic (hardware) triggering and its TriggerEnabled property is true, that tool will acquire images when triggers are received, even if the job is not running.
You can prevent this from happening by making sure that the TriggerEnabled property is set to false for all persisted jobs.
工作挂起
Job Hangs
如果使用嵌入式CogAcqFifo工具运行作业,并且CogAcqFifo工具的TriggerEnable属性为false,则无论触发器的类型如何,该作业都将挂起以等待该工具中的图像。 禁用触发器后,该工具将一直阻塞,直到达到超时为止;如果未指定超时,则将永远终止。
您可以通过在作业运行之前为所有嵌入式CogAcqFifo工具启用触发器来防止这种情况的发生。 最简单的方法是通过设置作业脚本。
下面的代码显示了如何设置一对事件处理程序,这些事件处理程序在作业运行时为作业的嵌入式CogAcqFifo工具启用触发器,并在作业完成时禁用触发器。 您可以通过在“配置作业属性”对话框中单击“编辑作业脚本”来访问作业脚本编辑器。)
注意:您必须在脚本中添加对Cognex.VisionPro.ToolGroup的引用。
If you run a job with an embedded CogAcqFifo tool, and the CogAcqFifo tool's TriggerEnable property is false, the job will hang waiting for an image from that tool, regardless of the type of trigger. When triggers are disabled, the tool will block until its timeout is reached, or forever, if no timeout is specified.
You can prevent this from happening by enabling triggers for all embedded CogAcqFifo tools before the job runs. The simplest method for doing this is by setting the Job Script.
The code below shows how to set up a pair of event handlers that enable triggers for a job's embedded CogAcqFifo tools when the job runs, and disables triggers when the job completes. You access the Job Script editor by clicking Edit Job Script in the Configure Job Properties dialog box.)
Note: You must add a reference to Cognex.VisionPro.ToolGroup to the script.
#region "When the Script is Initialized"
//Perform any initialization required by your script here.
public override void Initialize(CogJob jobParam)
{
//DO NOT REMOVE - Call the base class implementation first - DO NOT REMOVE
base.Initialize(jobParam);
// Add event handler to job start event
jobParam.Running += new CogJob.CogJobRunningEventHandler(EnableEmbeddedTriggers);
// Add event handler to job complete event
jobParam.Stopped += new CogJob.CogJobStoppedEventHandler(DisableEmbeddedTriggers);
}
#endregion
#region Event Handlers
public void EnableEmbeddedTriggers(Object o, CogJobActionEventArgs e)
{
CogJob job = (CogJob) o;
CogToolGroup tg = job.VisionTool as CogToolGroup;
// Enable triggers for each FIFO
CogAcqFifoTool caft= tg.Tools["CogAcqFifoTool1"] as CogAcqFifoTool;
caft.Operator.OwnedTriggerParams.TriggerEnabled = true;
caft = tg.Tools["CogAcqFifoTool2"] as CogAcqFifoTool;
caft.Operator.OwnedTriggerParams.TriggerEnabled = true;
caft = tg.Tools["CogAcqFifoTool3"] as CogAcqFifoTool;
caft.Operator.OwnedTriggerParams.TriggerEnabled = true;
}
public void DisableEmbeddedTriggers(Object o, CogJobActionEventArgs e)
{
CogJob job = (CogJob) o;
CogToolGroup tg = job.VisionTool as CogToolGroup;
// Disable triggers for each FIFO
CogAcqFifoTool caft= tg.Tools["CogAcqFifoTool1"] as CogAcqFifoTool;
caft.Operator.OwnedTriggerParams.TriggerEnabled = false;
caft = tg.Tools["CogAcqFifoTool2"] as CogAcqFifoTool;
caft.Operator.OwnedTriggerParams.TriggerEnabled = false;
caft = tg.Tools["CogAcqFifoTool3"] as CogAcqFifoTool;
caft.Operator.OwnedTriggerParams.TriggerEnabled = false;
}
#endregion
使用运行连续块访问CogAcqFifo属性
Using Run Continuous Blocks Access to CogAcqFifo Properties
如果单击“作业管理器”或“作业编辑器”中的“运行连续”按钮,将无法使用嵌入式CogAcqFifo工具控件启用或禁用触发器,也无法刷新采集FIFO。 在启用或禁用触发器或刷新FIFO之前,必须退出运行连续模式。
注意:禁用或启用“运行连续”模式不会自动启用或禁用嵌入式CogAcqFifo工具的触发器;它会自动启用或禁用触发器。 您必须使用控件或编写脚本自行启用和禁用触发器。
If you click the Run Continuous button in the Job Manager or Job Editor, you will not be able to enable or disable triggers using the embedded CogAcqFifo tool controls, nor flush the acquisition FIFOs. You must exit Run Continuous mode before enabling or disabling triggers or flushing FIFOs.
Note: Disabling or enabling Run Continuous mode does not automatically enable or disable triggers for embedded CogAcqFifo tools; you must enable and disable triggers yourself, either using the control or by writing a script.
下一篇: txt文件怎样实现上传前预览