vuba.BaseGUI.trackbar

BaseGUI.trackbar(name, id, min, max)[source]

Add a trackbar to the interactive window.

Parameters
  • name (str) – Name of trackbar to add.

  • id (str) – Id of trackbar to add. This will be the key associated with the trackbar.

  • min (int) – Minimum limit of trackbar

  • max (int) – Maximum limit of trackbar

  • func (callable, optional) – Trackbar callback to be called whenever the trackbar is changed. If None, then a basic callback will be used that simply passes the trackbar value to the BaseGUI.method method.

Notes

This method can be called in much the same way as BaseGUI.method, either as a decorator or as a typical method call.

Examples

For these examples, we will use the same binary threshold viewer as used in BaseGUI.method:

>>> import vuba
>>> import numpy as np
>>> import cv2
>>> def threshold(gui):
...     frame = img.copy()
...     thresh_val = gui['thresh_val']
...     _, thresh = cv2.threshold(frame, thresh_val, 255, cv2.THRESH_BINARY)
...     return thresh
>>> img = np.random.randint(low=0, high=255, size=(500, 500), dtype=np.uint8)
>>> gui = vuba.BaseGUI('Binary threshold viewer')
>>> gui.method(threshold)

For applications where there is no additional processing on each trackbar call, we can simply supply None to BaseGUI.trackbar as follows:

>>> gui.trackbar('Threshold', id='thresh_val', min=0, max=255)(None)
>>> gui.run()

However, if we wanted to add some further processing, let’s say to exclude all odd threshold values, we could handle this logic with a custom callback:

>>> gui = vuba.BaseGUI('Binary threshold viewer')
>>> gui.method(threshold)
>>> @gui.trackbar('Threshold', id='thresh_val', min=0, max=255)
>>> def even_threshold(gui, val):
...     if val%2 == 0:
...         gui['thresh_val'] = val
...         ret = gui.process()
...         cv2.imshow(gui.title, ret)
>>> gui.run()
Return type

BaseGUI