跳转到内容

相机模拟#

相机模拟功能使您无需连接物理相机设备即可测试相机的基本功能,并创建测试图像。

可以使用 pylon API 和 pylon Viewer 访问仿真相机设备。

概述#

除了 GigE Vision 或 USB3 Vision 之类的相机传输层之外,pylon 还提供了可创建简单仿真相机设备的传输层。这使您无需物理相机即可开发应用。如果您要开发多相机应用,并且手头没有足够的相机,这也非常有用。

您最多可以创建 256 个仿真相机设备。

除了模拟图像采集和标准相机功能之外,仿真相机设备还提供物理相机不具备的功能:

启用相机模拟#

您可以在 pylon Viewer 和/或 pylon API 中启用相机模拟。

安装相机模拟支持#

  • 如果您正在使用 pylon Linux 版,默认情况下会安装相机模拟支持。
  • 如果您正在使用 pylon Windows 版并已通过运行时可再发行软件包安装 pylon,默认情况下会安装相机模拟支持。
  • 如果您正在使用 pylon Windows 版并已通过 pylon Camera Software Suite 安装程序安装 pylon:
    • 如果在安装过程中选择了相机用户开发人员配置文件,则默认情况下会安装相机模拟支持。
    • 如果在安装过程中选择了自定义配置文件,则只有在选择了相机模拟支持选项后,才会安装相机模拟支持。如果尚未选择此选项,请再次运行安装程序并选择该选项。

在 pylon Viewer 中启用相机模拟#

在 pylon Viewer 中启用相机模拟:

  1. 确保已安装相机模拟支持。
  2. 在 pylon Viewer 的工具菜单中,单击选项
  3. 选项对话框中,单击相机模拟
  4. 相机模拟页面上,输入所需仿真相机设备数量,然后单击确定
    短暂等待后,模拟设备将显示在设备窗格中。
    可以使用 pylon Viewer 访问这些设备。如果您还想访问 pylon API,请按照以下说明进行操作。

信息

如果将仿真相机设备的数量设置为 0,则相机模拟节点将不会显示在设备窗格中。

在 pylon API 中启用相机模拟#

在 pylon API 中启用相机模拟:

  1. 确保已安装相机模拟支持。
  2. Add a system environment variable named PYLON_CAMEMU and set its value to the desired number of emulation devices.
    Example: PYLON_CAMEMU=2
    This will provide two emulation devices.
    They can be accessed using the pylon API. If you also want to access the devices in the pylon Viewer, follow the instructions above.

信息

If PYLON_CAMEMU is not set or set to 0, no emulation devices will be available.

标准相机功能#

仿真相机设备可以模拟以下标准相机功能:

附加功能#

以下功能在仿真相机设备上可用,而在物理 Basler 相机上可用。

显示自定义测试图像#

除了显示标准测试图像之外,相机模拟还允许您显示从硬盘加载的自定义测试图像。

信息

  • Windows 上,可以加载以下图像文件格式:BMP、JPG、PNG 和 TIF。
  • Linux 上,可以加载以下图像文件格式:PNG 和 TIF。

要显示自定义测试图像:

  1. Set the TestImageSelector parameter to Off.
    This disables the use of standard test images.
  2. Set the ImageFileMode parameter to On.
    This enables the use of custom test images.
  3. If you want to display a single test image, provide the image file name, including the full path, in the ImageFilename parameter.
    Example: c:\images\my-test-image.png
  4. 如果您想要显示多个测试图像:

    1. 将所有要显示的测试图像放在一个目录中。
      该目录不得包含任何子目录。
    2. Provide the full path of the directory containing the files in the ImageFilename parameter.
      Example: c:\images\
  5. 至少采集一张图像以显示测试图像。如果要在 pylon Viewer 中显示测图像,请单击工具栏中的“单拍”或“连拍”按钮。

故障排除#

  • If the custom test image isn't displayed, i.e., the image displayed is completely black, then pylon couldn't load the file. Check the file name or path provided in the ImageFilename parameter. If you provided a directory name, make sure that the directory doesn't contain any subdirectories.
  • 如果自定义测试图像以单色显示,请切换为彩色像素格式(BGR/BGRA/RGB)。
  • If the custom test image isn't displayed in full size, adjust the image ROI parameters (Width, Height, OffsetX, and OffsetY).

生成失败的缓冲区#

强制失败的缓冲区功能使您可以通过生成失败的缓冲区来模拟不良的相机连接。比如说,这对于测试您的异常处理例程很有用。

要生成失败缓冲区:

  1. 开始图像采集。
  2. Set the ForceFailedBufferCount parameter to the number of failed buffers you want to generate.
  3. Execute the ForceFailedBuffer command.
    The camera emulation device will now generate corrupt images. The number of corrupt images depends on the value of the ForceFailedBufferCount parameter.

示例代码#

// ** 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 轻松设置参数。