VisionBox Interface Library  1.7.15.0 (2026-04-13)
Loading...
Searching...
No Matches
Python

How to use the Python bindings.

Note
Please take a look at the Linux / Windows SDK documentation on how to install the Python bindings.

The C++ classes and methods for this library are implemented by the Python module vib.

The Pyton API reference for the module briefly describes the function arguments and return values. Refer to this documentation for a detailed description.

C++ API comparison

  • C++ API:
    • All functions return a bool value to indicate success of each function.
    • Additional function results are returned by passing arguments by reference.
  • Python API:
    • Functions will raise a Python exception in case of an error.
    • Function results are regular return values of the function. Mupltiple result values are returned as a tuple.
    • Enumerations are implemented by enum.Enum objects.

Examples

Python examples can be found in the SDK folder:

  • Windows: <SDK installation folder>\python\examples
  • Linux: /opt/ImagoTechnologies/SDK/python/examples
FirstTest.py: a basic example which shows the serial number and sets digital outputs
#!/usr/bin/python3
# Prerequisites:
# On Linux, the python bindings for the VisionBox Interface Library (module 'vib') are installed
# automatically, if the package python3-pip is present during installation of the SDK.
# The bindings can be installed manually by running the following commands:
# $ apt install python3-pip
# $ python3 -m pip install --upgrade --no-index --find-links=file:///opt/ImagoTechnologies/SDK/python vib
# Import the vib module:
import vib
# Open the first Service device and read the serial number:
service = vib.Service()
service.Open(0)
print("Serial number: " + service.GetSerialNumber())
# Open the first DigitalOutput device and set the output value:
digitalOutput = vib.DigitalOutput()
digitalOutput.Open(0)
digitalOutput.Reset()
print("Setting digital output to 0x55")
digitalOutput.Set(0x55)
Led.py: this example configures the status LEDs
#!/usr/bin/python3
# Prerequisites: See FirstTest.py
# Import the vib module:
import vib
# Open the Led device
try:
led = vib.Led()
led.Open()
except:
print("The Led device cannot be openend / is not available")
exit
led.Reset()
print("Setting LED0: on")
led.SetLED(0, True)
print("Setting LED1: signal generator, blinking three times")
led.ConfigureGenerator(0, 3, 200, 200, 2000)
led.SetMode(1, led.MODE.GEN0)
DigitalIO.py: the Multiplexer is used to connect signals from DigitalInput to DigitalOutput
#!/usr/bin/python3
# This example connects Digital Input signals to Digital Outputs by using the Multiplexer.
# Prerequisites: See FirstTest.py
# Import the vib module:
import vib
print('Connecting DigitalInput to DigitalOutput as follows:')
print()
print('IN(0) --> Multiplexer(0) --+----------------> OUT(0)')
print(' |')
print(' |----(invert)----> OUT(1)')
print()
print('IN(1) --> Multiplexer(1) --+----------------> OUT(2)')
print(' |')
print(' |----(invert)----> OUT(3)')
# Open devices DigitalInput, DigitalOutput and Multiplexer:
digitalOutput = vib.DigitalOutput()
digitalOutput.Open(0)
digitalOutput.Reset()
multiplexer = vib.Multiplexer()
multiplexer.Open(0)
# Note: It's not required to open DigitalInput for this example, but we want
# to configure the debounce time:
digitalInput = vib.DigitalInput()
digitalInput.Open(0)
# Configure DigitalInput debounce time to 1 us:
digitalInput.ConfigureDebounceTime(1000, 1000)
# Connect two Multiplexer lines to DigitalInput 0 and 1:
multiplexer.ConnectOutput(0, multiplexer.SOURCE.DIG_IN0);
multiplexer.ConnectOutput(1, multiplexer.SOURCE.DIG_IN1);
# Configure multiplexer line 0 and 1 as source for the digital outputs:
digitalOutput.SetSource(0, digitalOutput.SOURCE.MUX_OUT0, False);
digitalOutput.SetSource(1, digitalOutput.SOURCE.MUX_OUT0, True);
digitalOutput.SetSource(2, digitalOutput.SOURCE.MUX_OUT1, False);
digitalOutput.SetSource(3, digitalOutput.SOURCE.MUX_OUT1, True);
Service_Watchdog.py: configures the watchog to reset the Multiplexer after timeout
#!/usr/bin/python3
# Prerequisites: See FirstTest.py
# This examples uses the Watchdog to reset the Multiplexer. The state of the Multiplexer
# is visible at the DigitalOutput OUT0.
import time
# Import the vib module:
import vib
# Open the Service device
service = vib.Service()
service.Open()
# Open the DigitalOutput device
digOut = vib.DigitalOutput()
digOut.Open()
digOut.Reset()
# Open the Multiplexer device
mux = vib.Multiplexer()
mux.Open()
# turn on Multiplexer line 0, it turns off after the Watchdog fires
mux.ConnectOutput(0, vib.Multiplexer.SOURCE.ON)
# connect OUT0 to Multiplexer line 0 and invert the signal (OUT0 goes high after the watchdog fires)
digOut.SetSource(0, digOut.SOURCE.MUX_OUT0, True)
try:
print("Configuring watchdog to reset the Multiplexer after 3 seconds")
service.WatchdogSetup(True, 3000, vib.Service.WDT_RESET_TYPE.MULTIPLEXER)
except:
print(" Error: Watchdog reset type for Multiplexer is not available")
exit
print("Waiting for Watchdog timeout to expire...")
while not service.WatchdogHasFired():
time.sleep(0.1)
print("The Watchdog has fired, OUT0 should be active now")
TriggerGenerator.py: configures the TriggerGenerator and outputs generated signals to DigitalOutput signals
#!/usr/bin/python3
# Prerequisites: See FirstTest.py
# Import the vib module:
import vib
# Open devices TriggerGenerator, DigitalOutput and Multiplexer:
triggerUnit = vib.TriggerGenerator()
triggerUnit.Open(0)
triggerUnit.Reset()
digitalOutput = vib.DigitalOutput()
digitalOutput.Open(0)
digitalOutput.Reset()
multiplexer = vib.Multiplexer()
multiplexer.Open(0)
multiplexer.Reset()
print('DigitalOutput 0: configure a generator to create a 10 Hz trigger signal')
# Configure Generator to create a 10 Hz signal:
triggerUnit.ConfigureSet("GenA_tLow=50ms GenA_tHigh=50ms");
# Connect the signal to output 0 of the trigger unit:
triggerUnit.ConfigureSet("TrigOut0_Mux=GenA");
print('DigitalOutput 1: configure a Divider to reduce the frequency of the signal by 5')
# Configure DividerA to divide the input signal 0 (Multiplexer line 0) by 5:
triggerUnit.ConfigureSet("DividerA=5,TrigIn0_Both"); # trigger on both edges
# Connect the signal to output 1 of the trigger unit, we have to go through 'MuxIntern':
triggerUnit.ConfigureSet("MuxIntern0=DividerA");
triggerUnit.ConfigureSet("TrigOut1_Mux=TrigIntern0");
print('DigitalOutput 2: configure Counter to generate a pulse after 8 trigger signals')
# Configure CounterA to generate a pulse after 8 trigger signals:
triggerUnit.ConfigureSet("CounterA=8,TrigIn0_Rising"); # maximum counter value, trigger on rising edge
triggerUnit.ConfigureSet("CounterA_ON=7"); # counter value for output = ON
triggerUnit.ConfigureSet("CounterA_OFF=8"); # counter value for output = OFF
triggerUnit.ConfigureSet("CounterA_Reset=Auto"); # automatic reset at maximum counter value
triggerUnit.ConfigureSet("CounterA_Start=On"); # start the counter
# Connect the signal to output 2 of the trigger unit, we have to go through 'MuxIntern':
triggerUnit.ConfigureSet("MuxIntern1=CounterA");
triggerUnit.ConfigureSet("TrigOut2_Mux=TrigIntern1");
print('DigitalOutput 3: configure LUT0 to mask the trigger signal with the output')
print(' of the divider')
# Configure a LUT to mask the trigger signal with the output of DividerA:
triggerUnit.ConfigureSet("LUT0=TrigIn0&TrigIntern0");
triggerUnit.ConfigureSet("MuxIntern2=LUT0");
# Connect the signal to output 3 of the trigger unit, we have to go through 'MuxIntern':
triggerUnit.ConfigureSet("TrigOut3_Mux=TrigIntern2");
# Connect Multilexer lines to output signals of the trigger unit:
multiplexer.ConnectOutput(0, multiplexer.SOURCE.TRIGGEN_OUT0);
multiplexer.ConnectOutput(1, multiplexer.SOURCE.TRIGGEN_OUT1);
multiplexer.ConnectOutput(2, multiplexer.SOURCE.TRIGGEN_OUT2);
multiplexer.ConnectOutput(3, multiplexer.SOURCE.TRIGGEN_OUT3);
# Configure multiplexer lines as source for the digital outputs:
digitalOutput.SetSource(0, digitalOutput.SOURCE.MUX_OUT0, False);
digitalOutput.SetSource(1, digitalOutput.SOURCE.MUX_OUT1, False);
digitalOutput.SetSource(2, digitalOutput.SOURCE.MUX_OUT2, False);
digitalOutput.SetSource(3, digitalOutput.SOURCE.MUX_OUT3, False);
IOScheduler_RequeueMode.py: configures the IOScheduler for automatic requeue mode
#!/usr/bin/python3
# Prerequisites: See FirstTest.py
# Import the vib module:
import vib
print('This examples uses an IOScheduler in automatic requeue mode.')
print('- A 10 Hz signal generator (TriggerGenerator) is used as trigger source for the IOScheduler.')
print('- This signal is copied to DigitalOutput 0')
print('- An output sequence of four pulses is pushed into the IOScheduler (output value 1)')
print('- The last entry resets the IOScheduler sequence itself (output value 2)')
print('- The output signal of the IOScheduler is copied to DigitalOutput 1')
# Open devices TriggerGenerator, DigitalOutput, Multiplexer and IOScheduler:
triggerUnit = vib.TriggerGenerator()
triggerUnit.Open(0)
triggerUnit.Reset()
digitalOutput = vib.DigitalOutput()
digitalOutput.Open(0)
digitalOutput.Reset()
multiplexer = vib.Multiplexer()
multiplexer.Open(0)
multiplexer.Reset()
ioScheduler = vib.IOScheduler()
ioScheduler.Open(0)
ioScheduler.Reset()
# Configure Generator to create a 10 Hz trigger signal:
triggerUnit.ConfigureSet("GenA_tLow=50ms GenA_tHigh=50ms");
# Connect the signal to the output of the trigger unit:
triggerUnit.ConfigureSet("TrigOut0_Mux=GenA");
# Connect Multilexer line 0 to the output signal of the trigger unit:
multiplexer.ConnectOutput(0, multiplexer.SOURCE.TRIGGEN_OUT0);
# Copy the trigger signal to digital output 0:
digitalOutput.SetSource(0, digitalOutput.SOURCE.MUX_OUT0, False);
# Configure the IOScheduler
# Select multiplexer line 0 as trigger source
ioScheduler.SetTriggerSource(0, False);
# Enable automatic requeue mode
ioScheduler.SetAutomaticRequeueMode(True)
# Use output 1 of the IOScheduler to reset the sequence, we have to go through the Multiplexer:
multiplexer.ConnectOutput(1, multiplexer.SOURCE.IOSCHEDULER_0_OUT1);
ioScheduler.SetCounterResetSource(ioScheduler.RST_SRC.MUX_OUT1, False, True)
# Stop IOScheduler counters until all values have been pushed
ioScheduler.SetCounterFreeze(True)
# Start IOScheduler unit
ioScheduler.Start()
# Push trigger postions and output values into the FIFO
ioScheduler.PushValue(1, 1)
ioScheduler.PushValue(2, 0)
ioScheduler.PushValue(4, 1)
ioScheduler.PushValue(6, 0)
ioScheduler.PushValue(9, 1)
ioScheduler.PushValue(12, 0)
ioScheduler.PushValue(16, 1)
ioScheduler.PushValue(20, 0)
ioScheduler.PushValue(25, 2) # reset the sequence
# Connect Multilexer line 2 to output 0 of the first IOScheduler:
multiplexer.ConnectOutput(2, multiplexer.SOURCE.IOSCHEDULER_0_OUT0);
# Configure multiplexer line 2 as source for the digital output 1:
digitalOutput.SetSource(1, digitalOutput.SOURCE.MUX_OUT2, False);
# Start IOScheduler counters now
ioScheduler.SetCounterFreeze(False)
CameraLink.py: a basic CameraLink acquisition example
#!/usr/bin/python3
# This example acquires images from a Camera Link camera.
# Prerequisites: See FirstTest.py
import vib
# Camera Link interface parameters:
cl_module_id = 0
cam_channel = 0
cl_mode = vib.CameraLinkIn.INMODE_TYPE.CL_1TAP_8BIT
cl_flags = vib.CameraLinkIn.INMODE_FLAGS.DEFAULT
# For line-scan camera use:
# cl_flags = vib.CameraLinkIn.INMODE_FLAGS.IGNORE_FVAL
width = 640
height = 480
buffers = 4
print("Initializing grabber...")
cl = vib.CameraLinkIn()
cl.Open(cl_module_id)
cl.ConfigureCLInput(cam_channel, cl_mode, cl_flags, width, height)
print("Allocating {} buffers and starting acquisition...".format(buffers))
for i in range(buffers):
buf = cl.AllocateImageBuffer(cam_channel)
cl.AddImageBufferForCapturing(cam_channel, buf)
frame = 0
print("Starting acquisition loop, press CTRL-C to stop the program.")
while True:
try:
# wait for the next frame
result = cl.WaitForImageBuffer(cam_channel, 1000)
ptr = result[0]
bufIsValid = result[1]
if ptr:
if not bufIsValid:
print("The camera image is broken")
cl.AddImageBufferForCapturing(cam_channel, ptr)
continue
else:
print("Acquisition timeout")
continue
frame = frame + 1
print("\rFrame: {}".format(frame), end = '')
# todo: work with the image, e.g.:
# image = np.ndarray((height, width), dtype=np.uint8, buffer=ptr)
# cv.imshow("Camera", image)
# add buffer to the acquisition queue again
cl.AddImageBufferForCapturing(cam_channel, ptr)
except KeyboardInterrupt:
break
print("Stopping acquisition...")
cl.AbortBufferUsage(cam_channel)
print("Releasing buffers...")
while True:
result = cl.WaitForImageBuffer(cam_channel, 0)
if result[0] is None:
break
cl.FreeImageBuffer(cam_channel, result[0])
print("End.")
CameraLink_Live_OpenCV.py: a CameraLink example using OpenCV to display the camera image
#!/usr/bin/python3
# This example uses OpenCV to acquire and display images from a Camera Link camera.
# Prerequisites: See FirstTest.py
import vib
try:
import numpy as np
import cv2 as cv
except:
raise RuntimeError("OpenCV not found, run 'apt install --no-install-recommends python3-opencv'")
# Camera Link interface parameters:
cl_module_id = 0
cam_channel = 0
cl_mode = vib.CameraLinkIn.INMODE_TYPE.CL_1TAP_8BIT
cl_flags = vib.CameraLinkIn.INMODE_FLAGS.DEFAULT
# For line-scan camera use:
# cl_flags = vib.CameraLinkIn.INMODE_FLAGS.IGNORE_FVAL
width = 640
height = 480
buffers = 4
print("Initializing grabber...")
cl = vib.CameraLinkIn()
cl.Open(cl_module_id)
cl.ConfigureCLInput(cam_channel, cl_mode, cl_flags, width, height)
print("Allocating {} buffers and starting acquisition...".format(buffers))
for i in range(buffers):
buf = cl.AllocateImageBuffer(cam_channel)
cl.AddImageBufferForCapturing(cam_channel, buf)
cv.namedWindow("Camera", cv.WINDOW_NORMAL | cv.WINDOW_KEEPRATIO)
cv.resizeWindow("Camera", width, height)
frame = 0
print("Press 'q' in window to stop")
while (cv.waitKey(1) != ord('q')):
# wait for the next frame
result = cl.WaitForImageBuffer(cam_channel, 1000)
ptr = result[0]
bufIsValid = result[1]
if ptr:
if not bufIsValid:
print("The camera image is broken")
cl.AddImageBufferForCapturing(cam_channel, ptr)
continue
else:
print("Acquisition timeout")
continue
frame = frame + 1
# show the image
image = np.ndarray((height, width), dtype=np.uint8, buffer=ptr).copy()
cv.putText(image, "Frame: {}".format(frame), (30, 50),
cv.FONT_HERSHEY_SIMPLEX, 1.4, (200, 200, 250), 2, cv.LINE_AA)
cv.imshow("Camera", image)
# add buffer to the acquisition queue again
cl.AddImageBufferForCapturing(cam_channel, ptr)
print("Stopping acquisition...")
cl.AbortBufferUsage(cam_channel)
print("Releasing buffers...")
while True:
result = cl.WaitForImageBuffer(cam_channel, 0)
if result[0] is None:
break
cl.FreeImageBuffer(cam_channel, result[0])
cv.destroyAllWindows()
print("End.")
ListAllDevices.py: shows all hardware components and devices
#!/usr/bin/python3
# Prerequisites: See FirstTest.py
# Import the vib module:
import vib
print("Searching for vib devices...")
systemInfo = vib.VIBSystem.GetSystemInfo()
for systemType in systemInfo:
for index in range(systemType.GetNumberEntities()):
system = vib.VIBSystem.CreateInstance(systemType.GetSystemType(), index)
print(" Found hardware component: {}, System type: {}, index: {}".format(system.GetHardwareType().name, systemType.GetSystemType().name, index))
for fwIndex in range(2):
try:
version = system.GetFirmwareVersion(fwIndex)
print(" Firmware version (component {}): {}.{}.{}.{}".format(fwIndex, version[0], version[1], version[2], version[3]))
except:
break
deviceInfo = system.GetDeviceInfo()
if len(deviceInfo) != system.GetNumberOfDeviceTypes():
raise RuntimeError("Number of device types failed (VIBSystem.GetNumberOfDeviceTypes() / (VIBSystem.GetDeviceInfo())")
for deviceType in deviceInfo:
print(" Found {} devices: {}".format(deviceType.GetNumberEntities(), deviceType.GetDeviceType().name))
vib.VIBSystem.DeleteInstance(system)