vuba.BaseGUI.method

BaseGUI.method(func)[source]

Add a main processing function to be executed on every trackbar call.

All trackbar functions should call the function that is wrapped in this decorator. As such changes made to a single trackbar, will propagate to this main processing function and the changes will be returned to the named window.

Parameters

func (callable) – Main processing function for the interface.

See also

BaseGUI.trackbar

Examples

To demonstrate this method’s usage as a decorator we can construct a simple binary threshold viewer for a random binary image:

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

Note that this method does not have to be used as a decorator:

>>> gui = vuba.BaseGUI('Binary threshold viewer')
>>> def threshold(gui):
...     frame = img.copy()
...     thresh_val = gui['thresh_val']
...     _, thresh = cv2.threshold(frame, thresh_val, 255, cv2.THRESH_BINARY)
...     return thresh
>>> gui.method(threshold)
>>> gui.trackbar('Threshold', id='thresh_val', min=0, max=255)(None)
>>> gui.run()

Also note that since we are not doing any additional processing on each trackbar call in the above two examples, we can supply None to the BaseGUI.trackbar decorator. This will default to using a simple callback that will pass the trackbar values to the main processing method and display the result in the interactive window.

Return type

BaseGUI