Python
eGrabber can also be used in Python.
Installation
The Python bindings for eGrabber are provided in a Pyhon wheel installation package (a .whl file) located in the python subdirectory of the eGrabber installation directory1. Depending on your Python setup, installation can be as easy as:
python -m pip install <PATH_TO_EGRABBER_WHL>
A first example
This example creates a grabber and displays basic information about the interface, device, and remote device modules it contains. This is the Python version of the first C++ eGrabber example:
from egrabber import * # 1
card_ix = 0
device_ix = 0
def showInfo():
gentl = EGenTL() # 2
grabber = EGrabber(gentl, card_ix, device_ix) # 3
card = grabber.interface.get('InterfaceID') # 4
dev = grabber.device.get('DeviceID') # 5
width = grabber.remote.get('Width') # 6
height = grabber.remote.get('Height') # 6
print('Interface: %s' % card)
print('Device: %s' % dev)
print('Resolution: %ix%i' % (width, height))
try: # 7
showInfo()
except Exception as e: # 7
print('error: %s' % e)
| 1. | Import the egrabber module. |
| 2. | Create an EGenTL object. This will locate, open, and initialize the GenTL producer (e.g., coaxlink.cti). |
| 3. | Create an EGrabber object. The constructor needs the gentl object created in step 2. It also takes as optional arguments the indices of the interface and device to use. |
| 4. | Use GenApi to find out the ID of the Coaxlink card. We want an answer from the interface module, so the get is done on grabber.interface. |
| 5. | Similarly, find out the ID of the device. This time, we use grabber.device to target the device module. |
| 6. | Finally, read the camera resolution. This time, we use grabber.remote since the values must be retrieved from the camera. |
| 7. | egrabber uses exceptions to report errors, so we wrap our code inside a try: ... except: ... block. |
Example of program output:
Interface: PC1633 - Coaxlink Quad G3 (2-camera) - KQG00014
Device: Device0
Resolution: 4096x4096
Differences between C++ and Python eGrabber
eGrabber classes
| C++ | Python |
|---|---|
EGrabber<>
|
EGrabber
|
EGrabber<CallbackOnDemand>
|
EGrabber
|
EGrabber<CallbackSingleThread>
|
- |
EGrabber<CallbackMultiThread>
|
- |
Buffer
|
Buffer
|
ScopedBuffer
|
Buffer used in a with-block |
EGrabber methods
| ● | In the C++ API, method names are written in camelCase. In Python, method names are written in lower_case. For example, the C++ reallocBuffers becomes realloc_buffers in Python. |
| ● | Event notification via callback functions is not available in the current eGrabber Python bindings. |
| ● | Other differences: |
| C++ | Python |
|---|---|
getInteger<MODULE>(f)
|
MODULE.get(f, dtype=int)
|
getFloat<MODULE>(f)
|
MODULE.get(f, dtype=float)
|
getString<MODULE>(f)
|
MODULE.get(f, dtype=str)
|
getStringList<MODULE>(f)
|
MODULE.get(f, dtype=list)
|
| - | MODULE.get(f, dtype=bool)
|
| - | MODULE.get(f)
|
setInteger<MODULE>(f, v)
|
MODULE.set(f, v)
|
setFloat<MODULE>(f, v)
|
MODULE.set(f, v)
|
setString<MODULE>(f, v)
|
MODULE.set(f, v)
|
execute<MODULE>(f)
|
MODULE.execute(f)
|
where MODULE can be replaced by system, interface, device, stream, or remote.