Camera Emulation

The Camera Emulation feature allows you to test basic camera features and create test images without having a physical camera device attached to your computer.

The camera emulation devices can be accessed using the pylon API and the pylon Viewer.

In this topic Hide

Overview

In addition to camera transport layers like GigE Vision or USB3 Vision, pylon offers a transport layer that can create simple camera emulation devices. This allows you to develop applications without the need for a physical camera. It is also useful if you want to develop a multi-camera application and don't have enough cameras at hand.

You can create up to 256 camera emulation devices.

Besides emulating image acquisition and standard camera features, camera emulation devices also offer features that a physical camera does not offer:

Enabling Camera Emulation

You can enable camera emulation in the pylon Viewer, in the pylon API, or both.

Installing Camera Emulation Support

Enabling Camera Emulation in the pylon Viewer

To enable camera emulation in the pylon Viewer:

  1. Make sure that camera emulation support is installed.
  2. In the Tools menu of the pylon Viewer, click Options.
  3. In the Options dialog, click Camera Emulation.
  4. On the Camera Emulation page, enter the desired number of camera emulation devices and click OK.
    The emulation devices will be visible in the Devices pane after a short wait.
    They can be accessed using the pylon Viewer. If you also want to access the devices in the pylon API, follow the instructions below.

If the number of camera emulation devices is set to 0, the Camera Emulation node will not be shown in the Devices pane.

Enabling Camera Emulation in the pylon API

To enable camera emulation in the pylon API:

  1. Make sure that camera emulation support is installed.
  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.

Standard Camera Features

Camera emulation devices can emulate the following standard camera features:

Additional Features

The following features are only available on camera emulation devices and not on physical Basler cameras.

Displaying Custom Test Images

In addition to displaying standard test images, camera emulation allows you to display custom test images that are loaded from disk.

To display a custom test image:

  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. If you want to display multiple test images:
    1. Place all test images to be displayed in a single directory.
      The directory must not contain any subdirectories.
    2. Provide the full path of the directory containing the files in the ImageFilename parameter.
      Example: c:\images\
  5. Acquire at least one image to display the test image(s). If you want to display the image(s) in the pylon Viewer, click the single or continuous shot button in the toolbar.

Troubleshooting

Generating Failed Buffers

The Force Failed Buffer feature allows you to simulate a bad camera connection by generating failed buffers. This can be useful, e.g., to test your exception handling routines.

To generate failed buffers:

  1. Start image acquisition.
  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.

External Links

Sample Code

/* Custom Test Images*/
// Disable standard test images
camera.TestImageSelector.SetValue(TestImageSelector_Off);
// Enable custom test images
camera.ImageFileMode.SetValue(ImageFileMode_Off);
// 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*/

CEnumerationPtr(nodemap.GetNode("TestImageSelector"))->FromString("Off");
// Enable custom test images
CEnumerationPtr(nodemap.GetNode("ImageFileMode"))->FromString("Off");
// Load custom test image from disk
CStringPtr(nodemap.GetNode("ImageFilename"))->SetValue("c:\images\image1.png");
/*Force Failed Buffer*/

CIntegerPtr(nodemap.GetNode("ForceFailedBufferCount"))->SetValue(40);
// Generate 40 failed buffers
CCommandPtr(nodemap.GetNode("ForceFailedBuffer"))->Execute();
/*Custom Test Images*/

camera.Parameters[PLCamera.TestImageSelector].SetValue(PLCamera.TestImageSelector.Off);
// Enable custom test images
camera.Parameters[PLCamera.ImageFileMode].SetValue(PLCamera.ImageFileMode.Off);
// Load custom test image from disk
camera.Parameters[PLCamera.ImageFilename].SetValue("c:\images\image1.png");
/*Force Failed Buffer*/

camera.Parameters[PLCamera.ForceFailedBufferCount].SetValue(40);
// Generate 40 failed buffers
camera.Parameters[PLCamera.ForceFailedBuffer].Execute();
/*Custom Test Images*/

Pylon.DeviceFeatureFromString(hdev, "TestImageSelector", "Off");
// Enable custom test images
Pylon.DeviceFeatureFromString(hdev, "ImageFileMode", "Off");
// Load custom test image from disk
Pylon.DeviceFeatureFromString(hdev, "ImageFilename", "c:\images\image1.png");
/*Force Failed Buffer*/

Pylon.DeviceSetIntegerFeature(hdev, "ForceFailedBufferCount", 40);
// Generate 40 failed buffers
Pylon.DeviceExecuteCommandFeature(hdev, "ForceFailedBuffer");
/* 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*/

errRes = PylonDeviceFeatureFromString(hdev, "TestImageSelector", "Off");
CHECK(errRes);
/* Enable custom test images */
errRes = PylonDeviceFeatureFromString(hdev, "ImageFileMode", "Off");
CHECK(errRes);
/* Load custom test image from disk */
errRes = PylonDeviceFeatureFromString(hdev, "ImageFilename", "c:\images\image1.png");
CHECK(errRes);
/*Force Failed Buffer*/

errRes = PylonDeviceSetIntegerFeature(hdev, "ForceFailedBufferCount", 40);
CHECK(errRes);
/* Generate 40 failed buffers */
errRes = PylonDeviceExecuteCommandFeature(hdev, "ForceFailedBuffer");
CHECK(errRes);

You can also use the pylon Viewer to easily set the parameters.