Module highgui

Source
Expand description

§High-level GUI

While OpenCV was designed for use in full-scale applications and can be used within functionally rich UI frameworks (such as Qt*, WinForms*, or Cocoa*) or without any UI at all, sometimes there it is required to try functionality quickly and visualize the results. This is what the HighGUI module has been designed for.

It provides easy interface to:

  • Create and manipulate windows that can display images and “remember” their content (no need to handle repaint events from OS).
  • Add trackbars to the windows, handle simple mouse events as well as keyboard commands.

§OpenGL support

§Qt New Functions

image

This figure explains new functionality implemented with Qt* GUI. The new GUI provides a statusbar, a toolbar, and a control panel. The control panel can have trackbars and buttonbars attached to it. If you cannot see the control panel, press Ctrl+P or right-click any Qt window and select Display properties window.

  • To attach a trackbar, the window name parameter must be NULL.

  • To attach a buttonbar, a button must be created. If the last bar attached to the control panel is a buttonbar, the new button is added to the right of the last button. If the last bar attached to the control panel is a trackbar, or the control panel is empty, a new buttonbar is created. Then, a new button is attached to it.

See below the example used to generate the figure:

@include highgui_qt.cpp

§WinRT support

This figure explains new functionality implemented with WinRT GUI. The new GUI provides an Image control, and a slider panel. Slider panel holds trackbars attached to it.

Sliders are attached below the image control. Every new slider is added below the previous one.

See below the example used to generate the figure:

void sample_app::MainPage::ShowWindow()
{
    static cv::String windowName("sample");
    cv::winrt_initContainer(this->cvContainer);
    cv::namedWindow(windowName); // not required

    cv::Mat image = cv::imread("Assets/sample.jpg");
    cv::Mat converted = cv::Mat(image.rows, image.cols, CV_8UC4);
    cv::cvtColor(image, converted, COLOR_BGR2BGRA);
    cv::imshow(windowName, converted); // this will create window if it hasn't been created before

    int state = 42;
    cv::TrackbarCallback callback = [](int pos, void* userdata)
    {
        if (pos == 0) {
            cv::destroyWindow(windowName);
        }
    };
    cv::TrackbarCallback callbackTwin = [](int pos, void* userdata)
    {
        if (pos >= 70) {
            cv::destroyAllWindows();
        }
    };
    cv::createTrackbar("Sample trackbar", windowName, &state, 100, callback);
    cv::createTrackbar("Twin brother", windowName, &state, 100, callbackTwin);
}

Modules§

prelude

Structs§

QtFont
QtFont available only for Qt. See cv::fontQt

Enums§

MouseEventFlags
Mouse Event Flags see cv::MouseCallback
MouseEventTypes
Mouse Events see cv::MouseCallback
QtButtonTypes
Qt “button” type
QtFontStyles
Qt font style
QtFontWeights
Qt font weight
WindowFlags
Flags for cv::namedWindow
WindowPropertyFlags
Flags for cv::setWindowProperty / cv::getWindowProperty

Constants§

EVENT_FLAG_ALTKEY
indicates that ALT Key is pressed.
EVENT_FLAG_CTRLKEY
indicates that CTRL Key is pressed.
EVENT_FLAG_LBUTTON
indicates that the left mouse button is down.
EVENT_FLAG_MBUTTON
indicates that the middle mouse button is down.
EVENT_FLAG_RBUTTON
indicates that the right mouse button is down.
EVENT_FLAG_SHIFTKEY
indicates that SHIFT Key is pressed.
EVENT_LBUTTONDBLCLK
indicates that left mouse button is double clicked.
EVENT_LBUTTONDOWN
indicates that the left mouse button is pressed.
EVENT_LBUTTONUP
indicates that left mouse button is released.
EVENT_MBUTTONDBLCLK
indicates that middle mouse button is double clicked.
EVENT_MBUTTONDOWN
indicates that the middle mouse button is pressed.
EVENT_MBUTTONUP
indicates that middle mouse button is released.
EVENT_MOUSEHWHEEL
positive and negative values mean right and left scrolling, respectively.
EVENT_MOUSEMOVE
indicates that the mouse pointer has moved over the window.
EVENT_MOUSEWHEEL
positive and negative values mean forward and backward scrolling, respectively.
EVENT_RBUTTONDBLCLK
indicates that right mouse button is double clicked.
EVENT_RBUTTONDOWN
indicates that the right mouse button is pressed.
EVENT_RBUTTONUP
indicates that right mouse button is released.
QT_CHECKBOX
Checkbox button.
QT_FONT_BLACK
Weight of 87
QT_FONT_BOLD
Weight of 75
QT_FONT_DEMIBOLD
Weight of 63
QT_FONT_LIGHT
Weight of 25
QT_FONT_NORMAL
Weight of 50
QT_NEW_BUTTONBAR
Button should create a new buttonbar
QT_PUSH_BUTTON
Push button.
QT_RADIOBOX
Radiobox button.
QT_STYLE_ITALIC
Italic font.
QT_STYLE_NORMAL
Normal font.
QT_STYLE_OBLIQUE
Oblique font.
WINDOW_AUTOSIZE
the user cannot resize the window, the size is constrainted by the image displayed.
WINDOW_FREERATIO
the image expends as much as it can (no ratio constraint).
WINDOW_FULLSCREEN
change the window to fullscreen.
WINDOW_GUI_EXPANDED
status bar and tool bar
WINDOW_GUI_NORMAL
old fashious way
WINDOW_KEEPRATIO
the ratio of the image is respected.
WINDOW_NORMAL
the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size.
WINDOW_OPENGL
window with opengl support.
WND_PROP_ASPECT_RATIO
window’s aspect ration (can be set to WINDOW_FREERATIO or WINDOW_KEEPRATIO).
WND_PROP_AUTOSIZE
autosize property (can be WINDOW_NORMAL or WINDOW_AUTOSIZE).
WND_PROP_FULLSCREEN
fullscreen property (can be WINDOW_NORMAL or WINDOW_FULLSCREEN).
WND_PROP_OPENGL
opengl support.
WND_PROP_TOPMOST
property to toggle normal window being topmost or not
WND_PROP_VISIBLE
checks whether the window exists and is visible
WND_PROP_VSYNC
enable or disable VSYNC (in OpenGL mode)

Traits§

QtFontTrait
Mutable methods for crate::highgui::QtFont
QtFontTraitConst
Constant methods for crate::highgui::QtFont

Functions§

add_text
Draws a text on the image.
add_text_with_font
Draws a text on the image.
add_text_with_font_def
Draws a text on the image.
create_button
Attaches a button to the control panel.
create_button_def
Attaches a button to the control panel.
create_trackbar
Creates a trackbar and attaches it to the specified window.
current_ui_framework
HighGUI backend used.
destroy_all_windows
Destroys all of the HighGUI windows.
destroy_window
Destroys the specified window.
display_overlay
Displays a text on a window image as an overlay for a specified duration.
display_overlay_def
Displays a text on a window image as an overlay for a specified duration.
display_status_bar
Displays a text on the window statusbar during the specified period of time.
display_status_bar_def
Displays a text on the window statusbar during the specified period of time.
font_qt
Creates the font to draw a text on an image.
font_qt_def
Creates the font to draw a text on an image.
get_mouse_wheel_delta
Gets the mouse-wheel motion delta, when handling mouse-wheel events cv::EVENT_MOUSEWHEEL and cv::EVENT_MOUSEHWHEEL.
get_trackbar_pos
Returns the trackbar position.
get_window_image_rect
Provides rectangle of image in the window.
get_window_property
Provides parameters of a window.
imshow
Displays an image in the specified window.
load_window_parameters
Loads parameters of the specified window.
move_window
Moves the window to the specified position
named_window
Creates a window.
named_window_def
Creates a window.
poll_key
Polls for a pressed key.
resize_window
Resizes the window to the specified size
resize_window_size
Resizes the window to the specified size
save_window_parameters
Saves parameters of the specified window.
select_ro_is
Allows users to select multiple ROIs on the given image.
select_ro_is_def
Allows users to select multiple ROIs on the given image.
select_roi
Allows users to select a ROI on the given image.
select_roi_1
Allows users to select a ROI on the given image.
select_roi_1_def
@overload
select_roi_def
Allows users to select a ROI on the given image.
set_mouse_callback
@example samples/cpp/create_mask.cpp This program demonstrates using mouse events and how to make and use a mask image (black and white) .
set_opengl_context
Sets the specified window as current OpenGL context.
set_opengl_draw_callback
Sets a callback function to be called to draw on top of displayed image.
set_trackbar_max
Sets the trackbar maximum position.
set_trackbar_min
Sets the trackbar minimum position.
set_trackbar_pos
Sets the trackbar position.
set_window_property
Changes parameters of a window dynamically.
set_window_title
Updates window title
start_loop
start_window_thread
stop_loop
update_window
Force window to redraw its context and call draw callback ( See cv::setOpenGlDrawCallback ).
wait_key
Waits for a pressed key.
wait_key_def
Waits for a pressed key.
wait_key_ex
Similar to #waitKey, but returns full key code.
wait_key_ex_def
Similar to #waitKey, but returns full key code.

Type Aliases§

ButtonCallback
Callback function for a button created by cv::createButton
MouseCallback
Callback function for mouse events. see cv::setMouseCallback
OpenGlDrawCallback
Callback function defined to be called every frame. See cv::setOpenGlDrawCallback
TrackbarCallback
Callback function for Trackbar see cv::createTrackbar