vuba.FrameGUI

class vuba.FrameGUI(frame, *args, **kwargs)[source]

Class for creating interfaces for individual image manipulation.

Parameters
  • frame (ndarray) – Frame(s) to manipulate within the interface.

  • title (str) – Title of the interface window.

Returns

gui – Class object for creating the interactive window.

Return type

FrameGUI

Notes

This class does not impose any restrictions on the types/formats of the images you supply upon initiation. As such, we can supply a tuple or list of images that we want to manipulate at the same time for example (see examples below).

Examples

As in other single image examples, we will use a series of randomly generated binary images with a variable binary threshold in the interfaces below:

>>> import vuba
>>> import numpy as np
>>> import cv2
>>> img = np.random.randint(low=0, high=255, size=(500, 500), dtype=np.uint8)
>>> gui = vuba.FrameGUI(img, 'Binary threshold viewer')
>>> @gui.method
>>> def threshold(gui):
...     frame = gui.frame.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()

As mentioned above, we can supply a series of images for simultaneuous manipulation as well:

>>> img1 = np.random.randint(low=0, high=255, size=(500, 500), dtype=np.uint8)
>>> img2 = np.random.randint(low=0, high=255, size=(500, 500), dtype=np.uint8)
>>> gui = vuba.FrameGUI((img1, img2), 'Binary threshold viewer')
>>> @gui.method
>>> def threshold(gui):
...     frame1, frame2 = gui.img
...     thresh_val = gui['thresh_val']
...     _, thresh1 = cv2.threshold(frame1.copy(), thresh_val, 255, cv2.THRESH_BINARY)
...     _, thresh2 = cv2.threshold(frame2.copy(), thresh_val, 255, cv2.THRESH_BINARY)
...     return np.hstack((thresh1, thresh2))
>>> gui.trackbar('Threshold', id='thresh_val', min=0, max=255)(None)
>>> gui.run()

For an extension of this type of interface with drawing in addition, see /examples/interfaces/binarythreshod_viewer_with_drawing_video.py.

__init__(frame, *args, **kwargs)[source]

Methods

__init__(frame, *args, **kwargs)

method(func)

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

run()

Launch the interface.

trackbar(name, id, min, max)

Add a trackbar to the interactive window.

values()

Retrieve all current trackbar values from the interface.