![]() |
IDS peak genericC++ v1.9.0
|
To use IDS peak genericAPI in Python, the ids_peak package can be installed directly from PyPI via pip, Python's package manager:
pip must be installed in version 20.3 or greater. Otherwise pip will detect the wheel as "not supported on this platform".In case of an offline installation, there is a separate Python wheel for each supported Python version and CPU architecture. A Python wheel is a package file (with .whl file ending) which can be installed via pip, Python's package manager. Just call pip install <Path-To-Python-Wheel> to install your chosen Python wheel. The respective .whl file can be obtained from the package's PyPI project page under Download files.
While pip will inform you about missing packages and their version requirements, contrary to the online installation, you need to manually resolve dependencies and respect the correct order of installation.
To finally use IDS peak genericAPI in your Python script, just add import ids_peak.ids_peak or import ids_peak.ids_peak as some_alias at the top of your Python script. The latter should be preferred.
The Python API works much like the C++ API. Nearly the same principles, class and method names apply. For example, listing all available devices:
It is possible to convert the content of a Buffer into an image by directly employing Buffer::BasePtr alongside a custom conversion routine to ensure compatibility with any image processing library. However, the recommended method is to use the BufferToImage function. This function is included in the supplementary module ids_peak_ipl_extension. BufferToImage is specifically engineered to simplify the conversion process of raw memory data stored within a Buffer into an peak::ipl::Image that can be used for further processing.
An example usage could look like as follows:
image still uses the underlying memory of buffer. For this reason, you must ensure that you do not re-queue the buffer until you have finished processing image.There are only a few differences between the C++ API and the Python API. The most important ones are listed here:
The C++ API utilizes smart pointers for deterministic memory management, where the last smart pointer that holds a reference to the object destroys it when the smart pointer goes out of scope.
To close a module (e.g. the Device), you have to release all its shared_ptr instances (out-of-scope, call reset(), set to nullptr), then the module closes immediately.
Since Python uses garbage collection, when an object is released in Python, it won't be closed and deleted immediately. Instead, it will be deleted at some point in the future, when the garbage collection deems it necessary. Often, that's no problem. But if it is, you could do the following:
Since Python had no native concept of enumeration types, the values are mapped to individual constants. A rule of thumb is that each scope resolution operator :: in C++ is replaced with an underscore in Python:
To be notified when certain events happen, the C++ API employs callbacks that you have to register and unregister. This concept exists almost equivalently in the Python API. Likewise it's necessary to store the callback handle for subsequent unregistering of the callback.