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:

    int main(int argc, char *argv[])
    {

        int value = 50;
        int value2 = 0;


        namedWindow("main1",WINDOW_NORMAL);
        namedWindow("main2",WINDOW_AUTOSIZE | WINDOW_GUI_NORMAL);
        createTrackbar( "track1", "main1", &value, 255,  NULL);

        String nameb1 = "button1";
        String nameb2 = "button2";

        createButton(nameb1,callbackButton,&nameb1,QT_CHECKBOX,1);
        createButton(nameb2,callbackButton,NULL,QT_CHECKBOX,0);
        createTrackbar( "track2", NULL, &value2, 255, NULL);
        createButton("button5",callbackButton1,NULL,QT_RADIOBOX,0);
        createButton("button6",callbackButton2,NULL,QT_RADIOBOX,1);

        setMouseCallback( "main2",on_mouse,NULL );

        Mat img1 = imread("files/flower.jpg");
        VideoCapture video;
        video.open("files/hockey.avi");

        Mat img2,img3;

        while( waitKey(33) != 27 )
        {
            img1.convertTo(img2,-1,1,value);
            video >> img3;

            imshow("main1",img2);
            imshow("main2",img3);
        }

        destroyAllWindows();

        return 0;
    }

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);
    }

C API

Modules

Structs

QtFont available only for Qt. See cv::fontQt

Enums

Mouse Event Flags see cv::MouseCallback
Mouse Events see cv::MouseCallback
Qt “button” type
Qt font style
Qt font weight
Flags for cv::namedWindow
Flags for cv::setWindowProperty / cv::getWindowProperty

Constants

indicates that ALT Key is pressed.
indicates that CTRL Key is pressed.
indicates that the left mouse button is down.
indicates that the middle mouse button is down.
indicates that the right mouse button is down.
indicates that SHIFT Key is pressed.
indicates that left mouse button is double clicked.
indicates that the left mouse button is pressed.
indicates that left mouse button is released.
indicates that middle mouse button is double clicked.
indicates that the middle mouse button is pressed.
indicates that middle mouse button is released.
positive and negative values mean right and left scrolling, respectively.
indicates that the mouse pointer has moved over the window.
positive and negative values mean forward and backward scrolling, respectively.
indicates that right mouse button is double clicked.
indicates that the right mouse button is pressed.
indicates that right mouse button is released.
Checkbox button.
Weight of 87
Weight of 75
Weight of 63
Weight of 25
Weight of 50
Button should create a new buttonbar
Push button.
Radiobox button.
Italic font.
Normal font.
Oblique font.
the user cannot resize the window, the size is constrainted by the image displayed.
the image expends as much as it can (no ratio constraint).
change the window to fullscreen.
status bar and tool bar
old fashious way
the ratio of the image is respected.
the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size.
window with opengl support.
window’s aspect ration (can be set to WINDOW_FREERATIO or WINDOW_KEEPRATIO).
autosize property (can be WINDOW_NORMAL or WINDOW_AUTOSIZE).
fullscreen property (can be WINDOW_NORMAL or WINDOW_FULLSCREEN).
opengl support.
property to toggle normal window being topmost or not
checks whether the window exists and is visible
enable or disable VSYNC (in OpenGL mode)

Traits

QtFont available only for Qt. See cv::fontQt

Functions

Draws a text on the image.
Draws a text on the image.
Attaches a button to the control panel.
Creates a trackbar and attaches it to the specified window.
Destroys all of the HighGUI windows.
Destroys the specified window.
Displays a text on a window image as an overlay for a specified duration.
Displays a text on the window statusbar during the specified period of time.
Creates the font to draw a text on an image.
Gets the mouse-wheel motion delta, when handling mouse-wheel events cv::EVENT_MOUSEWHEEL and cv::EVENT_MOUSEHWHEEL.
Returns the trackbar position.
Provides rectangle of image in the window.
Provides parameters of a window.
Displays an image in the specified window.
Loads parameters of the specified window.
Moves the window to the specified position
Creates a window.
Polls for a pressed key.
Resizes the window to the specified size
Resizes the window to the specified size
Saves parameters of the specified window.
Allows users to select a ROI on the given image.
Allows users to select a ROI on the given image.
Allows users to select multiple ROIs on the given image.
@example samples/cpp/create_mask.cpp This program demonstrates using mouse events and how to make and use a mask image (black and white) .
Sets the specified window as current OpenGL context.
Sets a callback function to be called to draw on top of displayed image.
Sets the trackbar maximum position.
Sets the trackbar minimum position.
Sets the trackbar position.
Changes parameters of a window dynamically.
Updates window title
Force window to redraw its context and call draw callback ( See cv::setOpenGlDrawCallback ).
Waits for a pressed key.
Similar to #waitKey, but returns full key code.

Type Definitions

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