concepts.gui.opencv.simple_text_visualizer.CV2SimpleTextVisualizer#

class CV2SimpleTextVisualizer[source]#

Bases: object

A simple visualizer for text. The class should be initialized with a callback function, which takes the image and the mouse position as input, and returns the text to be displayed. The visualizer will display the image and the text.

Example

def callback(image, x, y):
    return f'Pixel value: {image[y, x]} (x={x}, y={y})'

visualizer = SimpleTextVisualizer(callback)
visualizer.run(image)

Methods

on_mouse_event(event, x, y, flags, param)

run(image)

Attributes

title

The title of the window.

image

The image currently being displayed.

__init__(callback, title=None, font=cv2.FONT_HERSHEY_SIMPLEX, font_scale=1, font_thickness=2)[source]#

Initialize the visualizer.

Parameters:
  • callback – the callback function.

  • title (str | None) – the title of the window.

  • font (int) – the font of the text.

  • font_scale (int) – the scale of the font.

  • font_thickness (int) – the thickness of the font.

__new__(**kwargs)#
on_mouse_event(event, x, y, flags, param)[source]#
run(image)[source]#
Parameters:

image (ndarray)

image: ndarray | None#

The image currently being displayed.

title: str#

The title of the window.