News

Introduction to Basler Cameras and PyPylon

3 min read
A man does programming on a laptop

Basler’s diverse camera range, suitable for applications such as microscopy, security, and computer vision is enhanced by its user-friendly software development kit. This simplifies integration into various projects. The Python bindings for these drivers, provided through PyPylon, demonstrate Basler’s commitment to supporting Python developers. This guide aims to familiarize you with the basics of these cameras and the Pylon Viewer to expedite your development process.

Installation Process for PyPylon

To utilize Basler cameras in Python projects, install PyPylon, the Python interface for Basler’s Pylon SDK. Recent enhancements have streamlined its installation, making it as straightforward as installing any standard Python package.

pip install pypylon

For specific version requirements or legacy code support, manual installation from GitHub remains an option.

Initial Steps: Identifying and Connecting Cameras

Commence by identifying the camera to be used, a crucial step for practicality and understanding driver-imposed patterns. Utilize the following Python snippet to list connected cameras, mirroring the output seen in the PylonViewer:

from pypylon import pylon
tl_factory = pylon.TlFactory.GetInstance()devices = tl_factory.EnumerateDevices()for device in devices:    print(device.GetFriendlyName())

This code enumerates connected devices, crucial for initial communication with a camera.

Image Acquisition Basics

To capture an image, create an InstantCamera object and attach the camera. Basler’s implementation simplifies handling the device’s life cycle and physical removal:

tl_factory = pylon.TlFactory.GetInstance()camera = pylon.InstantCamera()camera.Attach(tl_factory.CreateFirstDevice())

To acquire an image, follow these self-explanatory steps:

camera.Open()camera.StartGrabbing(1)grab = camera.RetrieveResult(2000, pylon.TimeoutHandling_Return)if grab.GrabSucceeded():    img = grab.GetArray()    print(f’Size of image: {img.shape}’)camera.Close()

Modifying Camera Parameters

Altering acquisition parameters like exposure time is straightforward with PyPylon’s intuitive syntax:

camera.ExposureTime.SetValue(50000)  # or camera.ExposureTime = 50000

Dealing with Common PyPylon Installation Issues

Be mindful of potential mismatches between Pylon and PyPylon versions. If encountered, local installation from the downloaded PyPylon code may resolve these issues:

$ export PYLON_ROOT=/opt/pylon$ python setup.py install

Advanced Usage: Callbacks and Free-Run Mode

For continuous image acquisition (free-run mode) or using callbacks for specific actions, PyPylon offers robust solutions. Implement callbacks for events like frame acquisition or camera initialization.

Buffer Management in PyPylon

Understanding buffer management is key to optimizing data flow between the camera and your application. PyPylon allows control over buffer size and management, essential for handling high frame rates or limited memory situations.

Comparative Table

Feature / SpecificationBasler CamerasOther Industry-Standard Cameras
Camera RangeWide range, suitable for microscopy, security, and computer visionTypically specialized for specific use-cases
Software IntegrationComes with a comprehensive software development kit for easy integrationVaries; some may require third-party software or have limited integration options
Python SupportStrong support with PyPylon, a dedicated Python libraryPython support varies; may not have dedicated libraries
Ease of InstallationStreamlined installation process for PyPylon; akin to standard Python packagesInstallation complexity varies; may require manual configuration
Image AcquisitionSimplified image acquisition with InstantCamera objectOften requires more complex setup and initialization
Parameter ModificationDirect and intuitive syntax for altering parameters like exposure timeMay require deeper understanding of camera’s SDK or less intuitive methods
Version CompatibilityRegular updates to ensure compatibility with latest Pylon versionFirmware and driver updates depend on manufacturer’s support
Advanced FeaturesSupports callbacks and free-run mode for advanced applicationsAdvanced features depend on the camera model and brand
Buffer ManagementExplicit control over buffer size and management, crucial for high FPS or limited memoryBuffer management capabilities can be limited or less transparent
User InterfacePylonViewer provides a comprehensive interface for parameter management and troubleshootingUser interface and ease of use can vary significantly

Conclusion

Basler’s commitment to Python integration, demonstrated by PyPylon, is commendable. The combination of PyPylon and the PylonViewer offers a powerful toolkit for camera integration and parameter management, simplifying the development of efficient, customized solutions.