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 / Specification | Basler Cameras | Other Industry-Standard Cameras |
---|---|---|
Camera Range | Wide range, suitable for microscopy, security, and computer vision | Typically specialized for specific use-cases |
Software Integration | Comes with a comprehensive software development kit for easy integration | Varies; some may require third-party software or have limited integration options |
Python Support | Strong support with PyPylon, a dedicated Python library | Python support varies; may not have dedicated libraries |
Ease of Installation | Streamlined installation process for PyPylon; akin to standard Python packages | Installation complexity varies; may require manual configuration |
Image Acquisition | Simplified image acquisition with InstantCamera object | Often requires more complex setup and initialization |
Parameter Modification | Direct and intuitive syntax for altering parameters like exposure time | May require deeper understanding of camera’s SDK or less intuitive methods |
Version Compatibility | Regular updates to ensure compatibility with latest Pylon version | Firmware and driver updates depend on manufacturer’s support |
Advanced Features | Supports callbacks and free-run mode for advanced applications | Advanced features depend on the camera model and brand |
Buffer Management | Explicit control over buffer size and management, crucial for high FPS or limited memory | Buffer management capabilities can be limited or less transparent |
User Interface | PylonViewer provides a comprehensive interface for parameter management and troubleshooting | User 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.