Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
highgui.hpp
00001 /*M/////////////////////////////////////////////////////////////////////////////////////// 00002 // 00003 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 00004 // 00005 // By downloading, copying, installing or using the software you agree to this license. 00006 // If you do not agree to this license, do not download, install, 00007 // copy or use the software. 00008 // 00009 // 00010 // License Agreement 00011 // For Open Source Computer Vision Library 00012 // 00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 00015 // Third party copyrights are property of their respective owners. 00016 // 00017 // Redistribution and use in source and binary forms, with or without modification, 00018 // are permitted provided that the following conditions are met: 00019 // 00020 // * Redistribution's of source code must retain the above copyright notice, 00021 // this list of conditions and the following disclaimer. 00022 // 00023 // * Redistribution's in binary form must reproduce the above copyright notice, 00024 // this list of conditions and the following disclaimer in the documentation 00025 // and/or other materials provided with the distribution. 00026 // 00027 // * The name of the copyright holders may not be used to endorse or promote products 00028 // derived from this software without specific prior written permission. 00029 // 00030 // This software is provided by the copyright holders and contributors "as is" and 00031 // any express or implied warranties, including, but not limited to, the implied 00032 // warranties of merchantability and fitness for a particular purpose are disclaimed. 00033 // In no event shall the Intel Corporation or contributors be liable for any direct, 00034 // indirect, incidental, special, exemplary, or consequential damages 00035 // (including, but not limited to, procurement of substitute goods or services; 00036 // loss of use, data, or profits; or business interruption) however caused 00037 // and on any theory of liability, whether in contract, strict liability, 00038 // or tort (including negligence or otherwise) arising in any way out of 00039 // the use of this software, even if advised of the possibility of such damage. 00040 // 00041 //M*/ 00042 00043 #ifndef __OPENCV_HIGHGUI_HPP__ 00044 #define __OPENCV_HIGHGUI_HPP__ 00045 00046 #include "opencv2/core.hpp" 00047 #include "opencv2/imgcodecs.hpp" 00048 #include "opencv2/videoio.hpp" 00049 00050 /** 00051 @defgroup highgui High-level GUI 00052 00053 While OpenCV was designed for use in full-scale applications and can be used within functionally 00054 rich UI frameworks (such as Qt\*, WinForms\*, or Cocoa\*) or without any UI at all, sometimes there 00055 it is required to try functionality quickly and visualize the results. This is what the HighGUI 00056 module has been designed for. 00057 00058 It provides easy interface to: 00059 00060 - Create and manipulate windows that can display images and "remember" their content (no need to 00061 handle repaint events from OS). 00062 - Add trackbars to the windows, handle simple mouse events as well as keyboard commands. 00063 00064 @{ 00065 @defgroup highgui_opengl OpenGL support 00066 @defgroup highgui_qt Qt New Functions 00067 00068  00069 00070 This figure explains new functionality implemented with Qt\* GUI. The new GUI provides a statusbar, 00071 a toolbar, and a control panel. The control panel can have trackbars and buttonbars attached to it. 00072 If you cannot see the control panel, press Ctrl+P or right-click any Qt window and select **Display 00073 properties window**. 00074 00075 - To attach a trackbar, the window name parameter must be NULL. 00076 00077 - To attach a buttonbar, a button must be created. If the last bar attached to the control panel 00078 is a buttonbar, the new button is added to the right of the last button. If the last bar 00079 attached to the control panel is a trackbar, or the control panel is empty, a new buttonbar is 00080 created. Then, a new button is attached to it. 00081 00082 See below the example used to generate the figure: 00083 @code 00084 int main(int argc, char *argv[]) 00085 { 00086 00087 int value = 50; 00088 int value2 = 0; 00089 00090 00091 namedWindow("main1",WINDOW_NORMAL); 00092 namedWindow("main2",WINDOW_AUTOSIZE | CV_GUI_NORMAL); 00093 createTrackbar( "track1", "main1", &value, 255, NULL); 00094 00095 String nameb1 = "button1"; 00096 String nameb2 = "button2"; 00097 00098 createButton(nameb1,callbackButton,&nameb1,QT_CHECKBOX,1); 00099 createButton(nameb2,callbackButton,NULL,QT_CHECKBOX,0); 00100 createTrackbar( "track2", NULL, &value2, 255, NULL); 00101 createButton("button5",callbackButton1,NULL,QT_RADIOBOX,0); 00102 createButton("button6",callbackButton2,NULL,QT_RADIOBOX,1); 00103 00104 setMouseCallback( "main2",on_mouse,NULL ); 00105 00106 Mat img1 = imread("files/flower.jpg"); 00107 VideoCapture video; 00108 video.open("files/hockey.avi"); 00109 00110 Mat img2,img3; 00111 00112 while( waitKey(33) != 27 ) 00113 { 00114 img1.convertTo(img2,-1,1,value); 00115 video >> img3; 00116 00117 imshow("main1",img2); 00118 imshow("main2",img3); 00119 } 00120 00121 destroyAllWindows(); 00122 00123 return 0; 00124 } 00125 @endcode 00126 00127 00128 @defgroup highgui_winrt WinRT support 00129 00130 This figure explains new functionality implemented with WinRT GUI. The new GUI provides an Image control, 00131 and a slider panel. Slider panel holds trackbars attached to it. 00132 00133 Sliders are attached below the image control. Every new slider is added below the previous one. 00134 00135 See below the example used to generate the figure: 00136 @code 00137 void sample_app::MainPage::ShowWindow() 00138 { 00139 static cv::String windowName("sample"); 00140 cv::winrt_initContainer(this->cvContainer); 00141 cv::namedWindow(windowName); // not required 00142 00143 cv::Mat image = cv::imread("Assets/sample.jpg"); 00144 cv::Mat converted = cv::Mat(image.rows, image.cols, CV_8UC4); 00145 cv::cvtColor(image, converted, COLOR_BGR2BGRA); 00146 cv::imshow(windowName, converted); // this will create window if it hasn't been created before 00147 00148 int state = 42; 00149 cv::TrackbarCallback callback = [](int pos, void* userdata) 00150 { 00151 if (pos == 0) { 00152 cv::destroyWindow(windowName); 00153 } 00154 }; 00155 cv::TrackbarCallback callbackTwin = [](int pos, void* userdata) 00156 { 00157 if (pos >= 70) { 00158 cv::destroyAllWindows(); 00159 } 00160 }; 00161 cv::createTrackbar("Sample trackbar", windowName, &state, 100, callback); 00162 cv::createTrackbar("Twin brother", windowName, &state, 100, callbackTwin); 00163 } 00164 @endcode 00165 00166 @defgroup highgui_c C API 00167 @} 00168 */ 00169 00170 ///////////////////////// graphical user interface ////////////////////////// 00171 namespace cv 00172 { 00173 00174 //! @addtogroup highgui 00175 //! @{ 00176 00177 //! Flags for cv::namedWindow 00178 enum WindowFlags { 00179 WINDOW_NORMAL = 0x00000000, //!< the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size. 00180 WINDOW_AUTOSIZE = 0x00000001, //!< the user cannot resize the window, the size is constrainted by the image displayed. 00181 WINDOW_OPENGL = 0x00001000, //!< window with opengl support. 00182 00183 WINDOW_FULLSCREEN = 1, //!< change the window to fullscreen. 00184 WINDOW_FREERATIO = 0x00000100, //!< the image expends as much as it can (no ratio constraint). 00185 WINDOW_KEEPRATIO = 0x00000000 //!< the ratio of the image is respected. 00186 }; 00187 00188 //! Flags for cv::setWindowProperty / cv::getWindowProperty 00189 enum WindowPropertyFlags { 00190 WND_PROP_FULLSCREEN = 0, //!< fullscreen property (can be WINDOW_NORMAL or WINDOW_FULLSCREEN). 00191 WND_PROP_AUTOSIZE = 1, //!< autosize property (can be WINDOW_NORMAL or WINDOW_AUTOSIZE). 00192 WND_PROP_ASPECT_RATIO = 2, //!< window's aspect ration (can be set to WINDOW_FREERATIO or WINDOW_KEEPRATIO). 00193 WND_PROP_OPENGL = 3 //!< opengl support. 00194 }; 00195 00196 //! Mouse Events see cv::MouseCallback 00197 enum MouseEventTypes { 00198 EVENT_MOUSEMOVE = 0, //!< indicates that the mouse pointer has moved over the window. 00199 EVENT_LBUTTONDOWN = 1, //!< indicates that the left mouse button is pressed. 00200 EVENT_RBUTTONDOWN = 2, //!< indicates that the right mouse button is pressed. 00201 EVENT_MBUTTONDOWN = 3, //!< indicates that the middle mouse button is pressed. 00202 EVENT_LBUTTONUP = 4, //!< indicates that left mouse button is released. 00203 EVENT_RBUTTONUP = 5, //!< indicates that right mouse button is released. 00204 EVENT_MBUTTONUP = 6, //!< indicates that middle mouse button is released. 00205 EVENT_LBUTTONDBLCLK = 7, //!< indicates that left mouse button is double clicked. 00206 EVENT_RBUTTONDBLCLK = 8, //!< indicates that right mouse button is double clicked. 00207 EVENT_MBUTTONDBLCLK = 9, //!< indicates that middle mouse button is double clicked. 00208 EVENT_MOUSEWHEEL = 10,//!< positive and negative values mean forward and backward scrolling, respectively. 00209 EVENT_MOUSEHWHEEL = 11 //!< positive and negative values mean right and left scrolling, respectively. 00210 }; 00211 00212 //! Mouse Event Flags see cv::MouseCallback 00213 enum MouseEventFlags { 00214 EVENT_FLAG_LBUTTON = 1, //!< indicates that the left mouse button is down. 00215 EVENT_FLAG_RBUTTON = 2, //!< indicates that the right mouse button is down. 00216 EVENT_FLAG_MBUTTON = 4, //!< indicates that the middle mouse button is down. 00217 EVENT_FLAG_CTRLKEY = 8, //!< indicates that CTRL Key is pressed. 00218 EVENT_FLAG_SHIFTKEY = 16,//!< indicates that SHIFT Key is pressed. 00219 EVENT_FLAG_ALTKEY = 32 //!< indicates that ALT Key is pressed. 00220 }; 00221 00222 //! Qt font weight 00223 enum QtFontWeights { 00224 QT_FONT_LIGHT = 25, //!< Weight of 25 00225 QT_FONT_NORMAL = 50, //!< Weight of 50 00226 QT_FONT_DEMIBOLD = 63, //!< Weight of 63 00227 QT_FONT_BOLD = 75, //!< Weight of 75 00228 QT_FONT_BLACK = 87 //!< Weight of 87 00229 }; 00230 00231 //! Qt font style 00232 enum QtFontStyles { 00233 QT_STYLE_NORMAL = 0, //!< Normal font. 00234 QT_STYLE_ITALIC = 1, //!< Italic font. 00235 QT_STYLE_OBLIQUE = 2 //!< Oblique font. 00236 }; 00237 00238 //! Qt "button" type 00239 enum QtButtonTypes { 00240 QT_PUSH_BUTTON = 0, //!< Push button. 00241 QT_CHECKBOX = 1, //!< Checkbox button. 00242 QT_RADIOBOX = 2 //!< Radiobox button. 00243 }; 00244 00245 /** @brief Callback function for mouse events. see cv::setMouseCallback 00246 @param event one of the cv::MouseEventTypes constants. 00247 @param x The x-coordinate of the mouse event. 00248 @param y The y-coordinate of the mouse event. 00249 @param flags one of the cv::MouseEventFlags constants. 00250 @param userdata The optional parameter. 00251 */ 00252 typedef void (*MouseCallback)(int event, int x, int y, int flags, void* userdata); 00253 00254 /** @brief Callback function for Trackbar see cv::createTrackbar 00255 @param pos current position of the specified trackbar. 00256 @param userdata The optional parameter. 00257 */ 00258 typedef void (*TrackbarCallback)(int pos, void* userdata); 00259 00260 /** @brief Callback function defined to be called every frame. See cv::setOpenGlDrawCallback 00261 @param userdata The optional parameter. 00262 */ 00263 typedef void (*OpenGlDrawCallback)(void* userdata); 00264 00265 /** @brief Callback function for a button created by cv::createButton 00266 @param state current state of the button. It could be -1 for a push button, 0 or 1 for a check/radio box button. 00267 @param userdata The optional parameter. 00268 */ 00269 typedef void (*ButtonCallback)(int state, void* userdata); 00270 00271 /** @brief Creates a window. 00272 00273 The function namedWindow creates a window that can be used as a placeholder for images and 00274 trackbars. Created windows are referred to by their names. 00275 00276 If a window with the same name already exists, the function does nothing. 00277 00278 You can call cv::destroyWindow or cv::destroyAllWindows to close the window and de-allocate any associated 00279 memory usage. For a simple program, you do not really have to call these functions because all the 00280 resources and windows of the application are closed automatically by the operating system upon exit. 00281 00282 @note 00283 00284 Qt backend supports additional flags: 00285 - **WINDOW_NORMAL or WINDOW_AUTOSIZE:** WINDOW_NORMAL enables you to resize the 00286 window, whereas WINDOW_AUTOSIZE adjusts automatically the window size to fit the 00287 displayed image (see imshow ), and you cannot change the window size manually. 00288 - **WINDOW_FREERATIO or WINDOW_KEEPRATIO:** WINDOW_FREERATIO adjusts the image 00289 with no respect to its ratio, whereas WINDOW_KEEPRATIO keeps the image ratio. 00290 - **CV_GUI_NORMAL or CV_GUI_EXPANDED:** CV_GUI_NORMAL is the old way to draw the window 00291 without statusbar and toolbar, whereas CV_GUI_EXPANDED is a new enhanced GUI. 00292 By default, flags == WINDOW_AUTOSIZE | WINDOW_KEEPRATIO | CV_GUI_EXPANDED 00293 00294 @param winname Name of the window in the window caption that may be used as a window identifier. 00295 @param flags Flags of the window. The supported flags are: (cv::WindowFlags) 00296 */ 00297 CV_EXPORTS_W void namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE); 00298 00299 /** @brief Destroys the specified window. 00300 00301 The function destroyWindow destroys the window with the given name. 00302 00303 @param winname Name of the window to be destroyed. 00304 */ 00305 CV_EXPORTS_W void destroyWindow(const String& winname); 00306 00307 /** @brief Destroys all of the HighGUI windows. 00308 00309 The function destroyAllWindows destroys all of the opened HighGUI windows. 00310 */ 00311 CV_EXPORTS_W void destroyAllWindows(); 00312 00313 CV_EXPORTS_W int startWindowThread(); 00314 00315 /** @brief Waits for a pressed key. 00316 00317 The function waitKey waits for a key event infinitely (when \f$\texttt{delay}\leq 0\f$ ) or for delay 00318 milliseconds, when it is positive. Since the OS has a minimum time between switching threads, the 00319 function will not wait exactly delay ms, it will wait at least delay ms, depending on what else is 00320 running on your computer at that time. It returns the code of the pressed key or -1 if no key was 00321 pressed before the specified time had elapsed. 00322 00323 @note 00324 00325 This function is the only method in HighGUI that can fetch and handle events, so it needs to be 00326 called periodically for normal event processing unless HighGUI is used within an environment that 00327 takes care of event processing. 00328 00329 @note 00330 00331 The function only works if there is at least one HighGUI window created and the window is active. 00332 If there are several HighGUI windows, any of them can be active. 00333 00334 @param delay Delay in milliseconds. 0 is the special value that means "forever". 00335 */ 00336 CV_EXPORTS_W int waitKey(int delay = 0); 00337 00338 /** @brief Displays an image in the specified window. 00339 00340 The function imshow displays an image in the specified window. If the window was created with the 00341 cv::WINDOW_AUTOSIZE flag, the image is shown with its original size, however it is still limited by the screen resolution. 00342 Otherwise, the image is scaled to fit the window. The function may scale the image, depending on its depth: 00343 00344 - If the image is 8-bit unsigned, it is displayed as is. 00345 - If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the 00346 value range [0,255\*256] is mapped to [0,255]. 00347 - If the image is 32-bit floating-point, the pixel values are multiplied by 255. That is, the 00348 value range [0,1] is mapped to [0,255]. 00349 00350 If window was created with OpenGL support, cv::imshow also support ogl::Buffer , ogl::Texture2D and 00351 cuda::GpuMat as input. 00352 00353 If the window was not created before this function, it is assumed creating a window with cv::WINDOW_AUTOSIZE. 00354 00355 If you need to show an image that is bigger than the screen resolution, you will need to call namedWindow("", WINDOW_NORMAL) before the imshow. 00356 00357 @note This function should be followed by cv::waitKey function which displays the image for specified 00358 milliseconds. Otherwise, it won't display the image. For example, **waitKey(0)** will display the window 00359 infinitely until any keypress (it is suitable for image display). **waitKey(25)** will display a frame 00360 for 25 ms, after which display will be automatically closed. (If you put it in a loop to read 00361 videos, it will display the video frame-by-frame) 00362 00363 @note 00364 00365 [__Windows Backend Only__] Pressing Ctrl+C will copy the image to the clipboard. 00366 00367 [__Windows Backend Only__] Pressing Ctrl+S will show a dialog to save the image. 00368 00369 @param winname Name of the window. 00370 @param mat Image to be shown. 00371 */ 00372 CV_EXPORTS_W void imshow(const String& winname, InputArray mat); 00373 00374 /** @brief Resizes window to the specified size 00375 00376 @note 00377 00378 - The specified window size is for the image area. Toolbars are not counted. 00379 - Only windows created without cv::WINDOW_AUTOSIZE flag can be resized. 00380 00381 @param winname Window name. 00382 @param width The new window width. 00383 @param height The new window height. 00384 */ 00385 CV_EXPORTS_W void resizeWindow(const String& winname, int width, int height); 00386 00387 /** @brief Moves window to the specified position 00388 00389 @param winname Name of the window. 00390 @param x The new x-coordinate of the window. 00391 @param y The new y-coordinate of the window. 00392 */ 00393 CV_EXPORTS_W void moveWindow(const String& winname, int x, int y); 00394 00395 /** @brief Changes parameters of a window dynamically. 00396 00397 The function setWindowProperty enables changing properties of a window. 00398 00399 @param winname Name of the window. 00400 @param prop_id Window property to edit. The supported operation flags are: (cv::WindowPropertyFlags) 00401 @param prop_value New value of the window property. The supported flags are: (cv::WindowFlags) 00402 */ 00403 CV_EXPORTS_W void setWindowProperty(const String& winname, int prop_id, double prop_value); 00404 00405 /** @brief Updates window title 00406 @param winname Name of the window. 00407 @param title New title. 00408 */ 00409 CV_EXPORTS_W void setWindowTitle(const String& winname, const String& title); 00410 00411 /** @brief Provides parameters of a window. 00412 00413 The function getWindowProperty returns properties of a window. 00414 00415 @param winname Name of the window. 00416 @param prop_id Window property to retrieve. The following operation flags are available: (cv::WindowPropertyFlags) 00417 00418 @sa setWindowProperty 00419 */ 00420 CV_EXPORTS_W double getWindowProperty(const String& winname, int prop_id); 00421 00422 /** @brief Sets mouse handler for the specified window 00423 00424 @param winname Name of the window. 00425 @param onMouse Mouse callback. See OpenCV samples, such as 00426 <https://github.com/Itseez/opencv/tree/master/samples/cpp/ffilldemo.cpp>, on how to specify and 00427 use the callback. 00428 @param userdata The optional parameter passed to the callback. 00429 */ 00430 CV_EXPORTS void setMouseCallback(const String& winname, MouseCallback onMouse, void* userdata = 0); 00431 00432 /** @brief Gets the mouse-wheel motion delta, when handling mouse-wheel events cv::EVENT_MOUSEWHEEL and 00433 cv::EVENT_MOUSEHWHEEL. 00434 00435 For regular mice with a scroll-wheel, delta will be a multiple of 120. The value 120 corresponds to 00436 a one notch rotation of the wheel or the threshold for action to be taken and one such action should 00437 occur for each delta. Some high-precision mice with higher-resolution freely-rotating wheels may 00438 generate smaller values. 00439 00440 For cv::EVENT_MOUSEWHEEL positive and negative values mean forward and backward scrolling, 00441 respectively. For cv::EVENT_MOUSEHWHEEL, where available, positive and negative values mean right and 00442 left scrolling, respectively. 00443 00444 With the C API, the macro CV_GET_WHEEL_DELTA(flags) can be used alternatively. 00445 00446 @note 00447 00448 Mouse-wheel events are currently supported only on Windows. 00449 00450 @param flags The mouse callback flags parameter. 00451 */ 00452 CV_EXPORTS int getMouseWheelDelta(int flags); 00453 00454 /** @brief Creates a trackbar and attaches it to the specified window. 00455 00456 The function createTrackbar creates a trackbar (a slider or range control) with the specified name 00457 and range, assigns a variable value to be a position synchronized with the trackbar and specifies 00458 the callback function onChange to be called on the trackbar position change. The created trackbar is 00459 displayed in the specified window winname. 00460 00461 @note 00462 00463 [__Qt Backend Only__] winname can be empty (or NULL) if the trackbar should be attached to the 00464 control panel. 00465 00466 Clicking the label of each trackbar enables editing the trackbar values manually. 00467 00468 @param trackbarname Name of the created trackbar. 00469 @param winname Name of the window that will be used as a parent of the created trackbar. 00470 @param value Optional pointer to an integer variable whose value reflects the position of the 00471 slider. Upon creation, the slider position is defined by this variable. 00472 @param count Maximal position of the slider. The minimal position is always 0. 00473 @param onChange Pointer to the function to be called every time the slider changes position. This 00474 function should be prototyped as void Foo(int,void\*); , where the first parameter is the trackbar 00475 position and the second parameter is the user data (see the next parameter). If the callback is 00476 the NULL pointer, no callbacks are called, but only value is updated. 00477 @param userdata User data that is passed as is to the callback. It can be used to handle trackbar 00478 events without using global variables. 00479 */ 00480 CV_EXPORTS int createTrackbar(const String& trackbarname, const String& winname, 00481 int* value, int count, 00482 TrackbarCallback onChange = 0, 00483 void* userdata = 0); 00484 00485 /** @brief Returns the trackbar position. 00486 00487 The function returns the current position of the specified trackbar. 00488 00489 @note 00490 00491 [__Qt Backend Only__] winname can be empty (or NULL) if the trackbar is attached to the control 00492 panel. 00493 00494 @param trackbarname Name of the trackbar. 00495 @param winname Name of the window that is the parent of the trackbar. 00496 */ 00497 CV_EXPORTS_W int getTrackbarPos(const String& trackbarname, const String& winname); 00498 00499 /** @brief Sets the trackbar position. 00500 00501 The function sets the position of the specified trackbar in the specified window. 00502 00503 @note 00504 00505 [__Qt Backend Only__] winname can be empty (or NULL) if the trackbar is attached to the control 00506 panel. 00507 00508 @param trackbarname Name of the trackbar. 00509 @param winname Name of the window that is the parent of trackbar. 00510 @param pos New position. 00511 */ 00512 CV_EXPORTS_W void setTrackbarPos(const String& trackbarname, const String& winname, int pos); 00513 00514 /** @brief Sets the trackbar maximum position. 00515 00516 The function sets the maximum position of the specified trackbar in the specified window. 00517 00518 @note 00519 00520 [__Qt Backend Only__] winname can be empty (or NULL) if the trackbar is attached to the control 00521 panel. 00522 00523 @param trackbarname Name of the trackbar. 00524 @param winname Name of the window that is the parent of trackbar. 00525 @param maxval New maximum position. 00526 */ 00527 CV_EXPORTS_W void setTrackbarMax(const String& trackbarname, const String& winname, int maxval); 00528 00529 /** @brief Sets the trackbar minimum position. 00530 00531 The function sets the minimum position of the specified trackbar in the specified window. 00532 00533 @note 00534 00535 [__Qt Backend Only__] winname can be empty (or NULL) if the trackbar is attached to the control 00536 panel. 00537 00538 @param trackbarname Name of the trackbar. 00539 @param winname Name of the window that is the parent of trackbar. 00540 @param minval New maximum position. 00541 */ 00542 CV_EXPORTS_W void setTrackbarMin(const String& trackbarname, const String& winname, int minval); 00543 00544 //! @addtogroup highgui_opengl OpenGL support 00545 //! @{ 00546 00547 /** @brief Displays OpenGL 2D texture in the specified window. 00548 00549 @param winname Name of the window. 00550 @param tex OpenGL 2D texture data. 00551 */ 00552 CV_EXPORTS void imshow(const String& winname, const ogl::Texture2D& tex); 00553 00554 /** @brief Sets a callback function to be called to draw on top of displayed image. 00555 00556 The function setOpenGlDrawCallback can be used to draw 3D data on the window. See the example of 00557 callback function below: 00558 @code 00559 void on_opengl(void* param) 00560 { 00561 glLoadIdentity(); 00562 00563 glTranslated(0.0, 0.0, -1.0); 00564 00565 glRotatef( 55, 1, 0, 0 ); 00566 glRotatef( 45, 0, 1, 0 ); 00567 glRotatef( 0, 0, 0, 1 ); 00568 00569 static const int coords[6][4][3] = { 00570 { { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } }, 00571 { { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 } }, 00572 { { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } }, 00573 { { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } }, 00574 { { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } }, 00575 { { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } } 00576 }; 00577 00578 for (int i = 0; i < 6; ++i) { 00579 glColor3ub( i*20, 100+i*10, i*42 ); 00580 glBegin(GL_QUADS); 00581 for (int j = 0; j < 4; ++j) { 00582 glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], 0.2 * coords[i][j][2]); 00583 } 00584 glEnd(); 00585 } 00586 } 00587 @endcode 00588 00589 @param winname Name of the window. 00590 @param onOpenGlDraw Pointer to the function to be called every frame. This function should be 00591 prototyped as void Foo(void\*) . 00592 @param userdata Pointer passed to the callback function.(__Optional__) 00593 */ 00594 CV_EXPORTS void setOpenGlDrawCallback(const String& winname, OpenGlDrawCallback onOpenGlDraw, void* userdata = 0); 00595 00596 /** @brief Sets the specified window as current OpenGL context. 00597 00598 @param winname Name of the window. 00599 */ 00600 CV_EXPORTS void setOpenGlContext(const String& winname); 00601 00602 /** @brief Force window to redraw its context and call draw callback ( See cv::setOpenGlDrawCallback ). 00603 00604 @param winname Name of the window. 00605 */ 00606 CV_EXPORTS void updateWindow(const String& winname); 00607 00608 //! @} highgui_opengl 00609 00610 //! @addtogroup highgui_qt 00611 //! @{ 00612 00613 /** @brief QtFont available only for Qt. See cv::fontQt 00614 */ 00615 struct QtFont 00616 { 00617 const char* nameFont; //!< Name of the font 00618 Scalar color; //!< Color of the font. Scalar(blue_component, green_component, red_component[, alpha_component]) 00619 int font_face; //!< See cv::QtFontStyles 00620 const int* ascii; //!< font data and metrics 00621 const int* greek; 00622 const int* cyrillic; 00623 float hscale, vscale; 00624 float shear; //!< slope coefficient: 0 - normal, >0 - italic 00625 int thickness; //!< See cv::QtFontWeights 00626 float dx; //!< horizontal interval between letters 00627 int line_type; //!< PointSize 00628 }; 00629 00630 /** @brief Creates the font to draw a text on an image. 00631 00632 The function fontQt creates a cv::QtFont object. This cv::QtFont is not compatible with putText . 00633 00634 A basic usage of this function is the following: : 00635 @code 00636 QtFont font = fontQt("Times"); 00637 addText( img1, "Hello World !", Point(50,50), font); 00638 @endcode 00639 00640 @param nameFont Name of the font. The name should match the name of a system font (such as 00641 *Times*). If the font is not found, a default one is used. 00642 @param pointSize Size of the font. If not specified, equal zero or negative, the point size of the 00643 font is set to a system-dependent default value. Generally, this is 12 points. 00644 @param color Color of the font in BGRA where A = 255 is fully transparent. Use the macro CV_RGB 00645 for simplicity. 00646 @param weight Font weight. Available operation flags are : cv::QtFontWeights You can also specify a positive integer for better control. 00647 @param style Font style. Available operation flags are : cv::QtFontStyles 00648 @param spacing Spacing between characters. It can be negative or positive. 00649 */ 00650 CV_EXPORTS QtFont fontQt(const String& nameFont, int pointSize = -1, 00651 Scalar color = Scalar::all(0), int weight = QT_FONT_NORMAL, 00652 int style = QT_STYLE_NORMAL, int spacing = 0); 00653 00654 /** @brief Draws a text on the image. 00655 00656 The function addText draws *text* on the image *img* using a specific font *font* (see example cv::fontQt 00657 ) 00658 00659 @param img 8-bit 3-channel image where the text should be drawn. 00660 @param text Text to write on an image. 00661 @param org Point(x,y) where the text should start on an image. 00662 @param font Font to use to draw a text. 00663 */ 00664 CV_EXPORTS void addText( const Mat& img, const String& text, Point org, const QtFont& font); 00665 00666 /** @brief Displays a text on a window image as an overlay for a specified duration. 00667 00668 The function displayOverlay displays useful information/tips on top of the window for a certain 00669 amount of time *delayms*. The function does not modify the image, displayed in the window, that is, 00670 after the specified delay the original content of the window is restored. 00671 00672 @param winname Name of the window. 00673 @param text Overlay text to write on a window image. 00674 @param delayms The period (in milliseconds), during which the overlay text is displayed. If this 00675 function is called before the previous overlay text timed out, the timer is restarted and the text 00676 is updated. If this value is zero, the text never disappears. 00677 */ 00678 CV_EXPORTS void displayOverlay(const String& winname, const String& text, int delayms = 0); 00679 00680 /** @brief Displays a text on the window statusbar during the specified period of time. 00681 00682 The function displayStatusBar displays useful information/tips on top of the window for a certain 00683 amount of time *delayms* . This information is displayed on the window statusbar (the window must be 00684 created with the CV_GUI_EXPANDED flags). 00685 00686 @param winname Name of the window. 00687 @param text Text to write on the window statusbar. 00688 @param delayms Duration (in milliseconds) to display the text. If this function is called before 00689 the previous text timed out, the timer is restarted and the text is updated. If this value is 00690 zero, the text never disappears. 00691 */ 00692 CV_EXPORTS void displayStatusBar(const String& winname, const String& text, int delayms = 0); 00693 00694 /** @brief Saves parameters of the specified window. 00695 00696 The function saveWindowParameters saves size, location, flags, trackbars value, zoom and panning 00697 location of the window windowName. 00698 00699 @param windowName Name of the window. 00700 */ 00701 CV_EXPORTS void saveWindowParameters(const String& windowName); 00702 00703 /** @brief Loads parameters of the specified window. 00704 00705 The function loadWindowParameters loads size, location, flags, trackbars value, zoom and panning 00706 location of the window windowName. 00707 00708 @param windowName Name of the window. 00709 */ 00710 CV_EXPORTS void loadWindowParameters(const String& windowName); 00711 00712 CV_EXPORTS int startLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]); 00713 00714 CV_EXPORTS void stopLoop(); 00715 00716 /** @brief Attaches a button to the control panel. 00717 00718 The function createButton attaches a button to the control panel. Each button is added to a 00719 buttonbar to the right of the last button. A new buttonbar is created if nothing was attached to the 00720 control panel before, or if the last element attached to the control panel was a trackbar. 00721 00722 See below various examples of the cv::createButton function call: : 00723 @code 00724 createButton(NULL,callbackButton);//create a push button "button 0", that will call callbackButton. 00725 createButton("button2",callbackButton,NULL,QT_CHECKBOX,0); 00726 createButton("button3",callbackButton,&value); 00727 createButton("button5",callbackButton1,NULL,QT_RADIOBOX); 00728 createButton("button6",callbackButton2,NULL,QT_PUSH_BUTTON,1); 00729 @endcode 00730 00731 @param bar_name Name of the button. 00732 @param on_change Pointer to the function to be called every time the button changes its state. 00733 This function should be prototyped as void Foo(int state,\*void); . *state* is the current state 00734 of the button. It could be -1 for a push button, 0 or 1 for a check/radio box button. 00735 @param userdata Pointer passed to the callback function. 00736 @param type Optional type of the button. Available types are: (cv::QtButtonTypes) 00737 @param initial_button_state Default state of the button. Use for checkbox and radiobox. Its 00738 value could be 0 or 1. (__Optional__) 00739 */ 00740 CV_EXPORTS int createButton( const String& bar_name, ButtonCallback on_change, 00741 void* userdata = 0, int type = QT_PUSH_BUTTON, 00742 bool initial_button_state = false); 00743 00744 //! @} highgui_qt 00745 00746 //! @} highgui 00747 00748 } // cv 00749 00750 #ifndef DISABLE_OPENCV_24_COMPATIBILITY 00751 #include "opencv2/highgui/highgui_c.h" 00752 #endif 00753 00754 #endif 00755
Generated on Tue Jul 12 2022 16:42:38 by
1.7.2