1 /*M/////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 // 5 // By downloading, copying, installing or using the software you agree to this license. 6 // If you do not agree to this license, do not download, install, 7 // copy or use the software. 8 // 9 // 10 // License Agreement 11 // For Open Source Computer Vision Library 12 // 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 // Third party copyrights are property of their respective owners. 16 // 17 // Redistribution and use in source and binary forms, with or without modification, 18 // are permitted provided that the following conditions are met: 19 // 20 // * Redistribution's of source code must retain the above copyright notice, 21 // this list of conditions and the following disclaimer. 22 // 23 // * Redistribution's in binary form must reproduce the above copyright notice, 24 // this list of conditions and the following disclaimer in the documentation 25 // and/or other materials provided with the distribution. 26 // 27 // * The name of the copyright holders may not be used to endorse or promote products 28 // derived from this software without specific prior written permission. 29 // 30 // This software is provided by the copyright holders and contributors "as is" and 31 // any express or implied warranties, including, but not limited to, the implied 32 // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 // In no event shall the Intel Corporation or contributors be liable for any direct, 34 // indirect, incidental, special, exemplary, or consequential damages 35 // (including, but not limited to, procurement of substitute goods or services; 36 // loss of use, data, or profits; or business interruption) however caused 37 // and on any theory of liability, whether in contract, strict liability, 38 // or tort (including negligence or otherwise) arising in any way out of 39 // the use of this software, even if advised of the possibility of such damage. 40 // 41 //M*/ 42 43 #ifndef __OPENCV_HIGHGUI_HPP__ 44 #define __OPENCV_HIGHGUI_HPP__ 45 46 #include "opencv2/core.hpp" 47 #include "opencv2/imgcodecs.hpp" 48 #include "opencv2/videoio.hpp" 49 50 /** 51 @defgroup highgui High-level GUI 52 53 While OpenCV was designed for use in full-scale applications and can be used within functionally 54 rich UI frameworks (such as Qt\*, WinForms\*, or Cocoa\*) or without any UI at all, sometimes there 55 it is required to try functionality quickly and visualize the results. This is what the HighGUI 56 module has been designed for. 57 58 It provides easy interface to: 59 60 - Create and manipulate windows that can display images and "remember" their content (no need to 61 handle repaint events from OS). 62 - Add trackbars to the windows, handle simple mouse events as well as keyboard commands. 63 64 @{ 65 @defgroup highgui_opengl OpenGL support 66 @defgroup highgui_qt Qt New Functions 67 68 ![image](pics/qtgui.png) 69 70 This figure explains new functionality implemented with Qt\* GUI. The new GUI provides a statusbar, 71 a toolbar, and a control panel. The control panel can have trackbars and buttonbars attached to it. 72 If you cannot see the control panel, press Ctrl+P or right-click any Qt window and select **Display 73 properties window**. 74 75 - To attach a trackbar, the window name parameter must be NULL. 76 77 - To attach a buttonbar, a button must be created. If the last bar attached to the control panel 78 is a buttonbar, the new button is added to the right of the last button. If the last bar 79 attached to the control panel is a trackbar, or the control panel is empty, a new buttonbar is 80 created. Then, a new button is attached to it. 81 82 See below the example used to generate the figure: : 83 @code 84 int main(int argc, char *argv[]) 85 int value = 50; 86 int value2 = 0; 87 88 cvNamedWindow("main1",CV_WINDOW_NORMAL); 89 cvNamedWindow("main2",CV_WINDOW_AUTOSIZE | CV_GUI_NORMAL); 90 91 cvCreateTrackbar( "track1", "main1", &value, 255, NULL);//OK tested 92 char* nameb1 = "button1"; 93 char* nameb2 = "button2"; 94 cvCreateButton(nameb1,callbackButton,nameb1,CV_CHECKBOX,1); 95 96 cvCreateButton(nameb2,callbackButton,nameb2,CV_CHECKBOX,0); 97 cvCreateTrackbar( "track2", NULL, &value2, 255, NULL); 98 cvCreateButton("button5",callbackButton1,NULL,CV_RADIOBOX,0); 99 cvCreateButton("button6",callbackButton2,NULL,CV_RADIOBOX,1); 100 101 cvSetMouseCallback( "main2",on_mouse,NULL ); 102 103 IplImage* img1 = cvLoadImage("files/flower.jpg"); 104 IplImage* img2 = cvCreateImage(cvGetSize(img1),8,3); 105 CvCapture* video = cvCaptureFromFile("files/hockey.avi"); 106 IplImage* img3 = cvCreateImage(cvGetSize(cvQueryFrame(video)),8,3); 107 108 while(cvWaitKey(33) != 27) 109 { 110 cvAddS(img1,cvScalarAll(value),img2); 111 cvAddS(cvQueryFrame(video),cvScalarAll(value2),img3); 112 cvShowImage("main1",img2); 113 cvShowImage("main2",img3); 114 } 115 116 cvDestroyAllWindows(); 117 cvReleaseImage(&img1); 118 cvReleaseImage(&img2); 119 cvReleaseImage(&img3); 120 cvReleaseCapture(&video); 121 return 0; 122 } 123 @endcode 124 125 @defgroup highgui_c C API 126 @} 127 */ 128 129 ///////////////////////// graphical user interface ////////////////////////// 130 namespace cv 131 { 132 133 //! @addtogroup highgui 134 //! @{ 135 136 // Flags for namedWindow 137 enum { WINDOW_NORMAL = 0x00000000, // the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size 138 WINDOW_AUTOSIZE = 0x00000001, // the user cannot resize the window, the size is constrainted by the image displayed 139 WINDOW_OPENGL = 0x00001000, // window with opengl support 140 141 WINDOW_FULLSCREEN = 1, // change the window to fullscreen 142 WINDOW_FREERATIO = 0x00000100, // the image expends as much as it can (no ratio constraint) 143 WINDOW_KEEPRATIO = 0x00000000 // the ratio of the image is respected 144 }; 145 146 // Flags for set / getWindowProperty 147 enum { WND_PROP_FULLSCREEN = 0, // fullscreen property (can be WINDOW_NORMAL or WINDOW_FULLSCREEN) 148 WND_PROP_AUTOSIZE = 1, // autosize property (can be WINDOW_NORMAL or WINDOW_AUTOSIZE) 149 WND_PROP_ASPECT_RATIO = 2, // window's aspect ration (can be set to WINDOW_FREERATIO or WINDOW_KEEPRATIO); 150 WND_PROP_OPENGL = 3 // opengl support 151 }; 152 153 enum { EVENT_MOUSEMOVE = 0, 154 EVENT_LBUTTONDOWN = 1, 155 EVENT_RBUTTONDOWN = 2, 156 EVENT_MBUTTONDOWN = 3, 157 EVENT_LBUTTONUP = 4, 158 EVENT_RBUTTONUP = 5, 159 EVENT_MBUTTONUP = 6, 160 EVENT_LBUTTONDBLCLK = 7, 161 EVENT_RBUTTONDBLCLK = 8, 162 EVENT_MBUTTONDBLCLK = 9, 163 EVENT_MOUSEWHEEL = 10, 164 EVENT_MOUSEHWHEEL = 11 165 }; 166 167 enum { EVENT_FLAG_LBUTTON = 1, 168 EVENT_FLAG_RBUTTON = 2, 169 EVENT_FLAG_MBUTTON = 4, 170 EVENT_FLAG_CTRLKEY = 8, 171 EVENT_FLAG_SHIFTKEY = 16, 172 EVENT_FLAG_ALTKEY = 32 173 }; 174 175 // Qt font 176 enum { QT_FONT_LIGHT = 25, //QFont::Light, 177 QT_FONT_NORMAL = 50, //QFont::Normal, 178 QT_FONT_DEMIBOLD = 63, //QFont::DemiBold, 179 QT_FONT_BOLD = 75, //QFont::Bold, 180 QT_FONT_BLACK = 87 //QFont::Black 181 }; 182 183 // Qt font style 184 enum { QT_STYLE_NORMAL = 0, //QFont::StyleNormal, 185 QT_STYLE_ITALIC = 1, //QFont::StyleItalic, 186 QT_STYLE_OBLIQUE = 2 //QFont::StyleOblique 187 }; 188 189 // Qt "button" type 190 enum { QT_PUSH_BUTTON = 0, 191 QT_CHECKBOX = 1, 192 QT_RADIOBOX = 2 193 }; 194 195 196 typedef void (*MouseCallback)(int event, int x, int y, int flags, void* userdata); 197 typedef void (*TrackbarCallback)(int pos, void* userdata); 198 typedef void (*OpenGlDrawCallback)(void* userdata); 199 typedef void (*ButtonCallback)(int state, void* userdata); 200 201 /** @brief Creates a window. 202 203 @param winname Name of the window in the window caption that may be used as a window identifier. 204 @param flags Flags of the window. The supported flags are: 205 > - **WINDOW_NORMAL** If this is set, the user can resize the window (no constraint). 206 > - **WINDOW_AUTOSIZE** If this is set, the window size is automatically adjusted to fit the 207 > displayed image (see imshow ), and you cannot change the window size manually. 208 > - **WINDOW_OPENGL** If this is set, the window will be created with OpenGL support. 209 210 The function namedWindow creates a window that can be used as a placeholder for images and 211 trackbars. Created windows are referred to by their names. 212 213 If a window with the same name already exists, the function does nothing. 214 215 You can call destroyWindow or destroyAllWindows to close the window and de-allocate any associated 216 memory usage. For a simple program, you do not really have to call these functions because all the 217 resources and windows of the application are closed automatically by the operating system upon exit. 218 219 @note 220 221 Qt backend supports additional flags: 222 - **CV_WINDOW_NORMAL or CV_WINDOW_AUTOSIZE:** CV_WINDOW_NORMAL enables you to resize the 223 window, whereas CV_WINDOW_AUTOSIZE adjusts automatically the window size to fit the 224 displayed image (see imshow ), and you cannot change the window size manually. 225 - **CV_WINDOW_FREERATIO or CV_WINDOW_KEEPRATIO:** CV_WINDOW_FREERATIO adjusts the image 226 with no respect to its ratio, whereas CV_WINDOW_KEEPRATIO keeps the image ratio. 227 - **CV_GUI_NORMAL or CV_GUI_EXPANDED:** CV_GUI_NORMAL is the old way to draw the window 228 without statusbar and toolbar, whereas CV_GUI_EXPANDED is a new enhanced GUI. 229 By default, flags == CV_WINDOW_AUTOSIZE | CV_WINDOW_KEEPRATIO | CV_GUI_EXPANDED 230 */ 231 CV_EXPORTS_W void namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE); 232 233 /** @brief Destroys a window. 234 235 @param winname Name of the window to be destroyed. 236 237 The function destroyWindow destroys the window with the given name. 238 */ 239 CV_EXPORTS_W void destroyWindow(const String& winname); 240 241 /** @brief Destroys all of the HighGUI windows. 242 243 The function destroyAllWindows destroys all of the opened HighGUI windows. 244 */ 245 CV_EXPORTS_W void destroyAllWindows(); 246 247 CV_EXPORTS_W int startWindowThread(); 248 249 /** @brief Waits for a pressed key. 250 251 @param delay Delay in milliseconds. 0 is the special value that means "forever". 252 253 The function waitKey waits for a key event infinitely (when \f$\texttt{delay}\leq 0\f$ ) or for delay 254 milliseconds, when it is positive. Since the OS has a minimum time between switching threads, the 255 function will not wait exactly delay ms, it will wait at least delay ms, depending on what else is 256 running on your computer at that time. It returns the code of the pressed key or -1 if no key was 257 pressed before the specified time had elapsed. 258 259 @note 260 261 This function is the only method in HighGUI that can fetch and handle events, so it needs to be 262 called periodically for normal event processing unless HighGUI is used within an environment that 263 takes care of event processing. 264 265 @note 266 267 The function only works if there is at least one HighGUI window created and the window is active. 268 If there are several HighGUI windows, any of them can be active. 269 */ 270 CV_EXPORTS_W int waitKey(int delay = 0); 271 272 /** @brief Displays an image in the specified window. 273 274 @param winname Name of the window. 275 @param mat Image to be shown. 276 277 The function imshow displays an image in the specified window. If the window was created with the 278 CV_WINDOW_AUTOSIZE flag, the image is shown with its original size, however it is still limited by the screen resolution. 279 Otherwise, the image is scaled to fit the window. The function may scale the image, depending on its depth: 280 281 - If the image is 8-bit unsigned, it is displayed as is. 282 - If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the 283 value range [0,255\*256] is mapped to [0,255]. 284 - If the image is 32-bit floating-point, the pixel values are multiplied by 255. That is, the 285 value range [0,1] is mapped to [0,255]. 286 287 If window was created with OpenGL support, imshow also support ogl::Buffer , ogl::Texture2D and 288 cuda::GpuMat as input. 289 290 If the window was not created before this function, it is assumed creating a window with CV_WINDOW_AUTOSIZE. 291 292 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. 293 294 @note This function should be followed by waitKey function which displays the image for specified 295 milliseconds. Otherwise, it won't display the image. For example, waitKey(0) will display the window 296 infinitely until any keypress (it is suitable for image display). waitKey(25) will display a frame 297 for 25 ms, after which display will be automatically closed. (If you put it in a loop to read 298 videos, it will display the video frame-by-frame) 299 300 @note 301 302 [Windows Backend Only] Pressing Ctrl+C will copy the image to the clipboard. 303 304 */ 305 CV_EXPORTS_W void imshow(const String& winname, InputArray mat); 306 307 /** @brief Resizes window to the specified size 308 309 @param winname Window name 310 @param width The new window width 311 @param height The new window height 312 313 @note 314 315 - The specified window size is for the image area. Toolbars are not counted. 316 - Only windows created without CV_WINDOW_AUTOSIZE flag can be resized. 317 */ 318 CV_EXPORTS_W void resizeWindow(const String& winname, int width, int height); 319 320 /** @brief Moves window to the specified position 321 322 @param winname Window name 323 @param x The new x-coordinate of the window 324 @param y The new y-coordinate of the window 325 */ 326 CV_EXPORTS_W void moveWindow(const String& winname, int x, int y); 327 328 /** @brief Changes parameters of a window dynamically. 329 330 @param winname Name of the window. 331 @param prop_id Window property to edit. The following operation flags are available: 332 - **CV_WND_PROP_FULLSCREEN** Change if the window is fullscreen ( CV_WINDOW_NORMAL or 333 CV_WINDOW_FULLSCREEN ). 334 - **CV_WND_PROP_AUTOSIZE** Change if the window is resizable (CV_WINDOW_NORMAL or 335 CV_WINDOW_AUTOSIZE ). 336 - **CV_WND_PROP_ASPECTRATIO** Change if the aspect ratio of the image is preserved ( 337 CV_WINDOW_FREERATIO or CV_WINDOW_KEEPRATIO ). 338 @param prop_value New value of the window property. The following operation flags are available: 339 - **CV_WINDOW_NORMAL** Change the window to normal size or make the window resizable. 340 - **CV_WINDOW_AUTOSIZE** Constrain the size by the displayed image. The window is not 341 resizable. 342 - **CV_WINDOW_FULLSCREEN** Change the window to fullscreen. 343 - **CV_WINDOW_FREERATIO** Make the window resizable without any ratio constraints. 344 - **CV_WINDOW_KEEPRATIO** Make the window resizable, but preserve the proportions of the 345 displayed image. 346 347 The function setWindowProperty enables changing properties of a window. 348 */ 349 CV_EXPORTS_W void setWindowProperty(const String& winname, int prop_id, double prop_value); 350 351 /** @brief Updates window title 352 */ 353 CV_EXPORTS_W void setWindowTitle(const String& winname, const String& title); 354 355 /** @brief Provides parameters of a window. 356 357 @param winname Name of the window. 358 @param prop_id Window property to retrieve. The following operation flags are available: 359 - **CV_WND_PROP_FULLSCREEN** Change if the window is fullscreen ( CV_WINDOW_NORMAL or 360 CV_WINDOW_FULLSCREEN ). 361 - **CV_WND_PROP_AUTOSIZE** Change if the window is resizable (CV_WINDOW_NORMAL or 362 CV_WINDOW_AUTOSIZE ). 363 - **CV_WND_PROP_ASPECTRATIO** Change if the aspect ratio of the image is preserved 364 (CV_WINDOW_FREERATIO or CV_WINDOW_KEEPRATIO ). 365 366 See setWindowProperty to know the meaning of the returned values. 367 368 The function getWindowProperty returns properties of a window. 369 */ 370 CV_EXPORTS_W double getWindowProperty(const String& winname, int prop_id); 371 372 /** @brief Sets mouse handler for the specified window 373 374 @param winname Window name 375 @param onMouse Mouse callback. See OpenCV samples, such as 376 <https://github.com/Itseez/opencv/tree/master/samples/cpp/ffilldemo.cpp>, on how to specify and 377 use the callback. 378 @param userdata The optional parameter passed to the callback. 379 */ 380 CV_EXPORTS void setMouseCallback(const String& winname, MouseCallback onMouse, void* userdata = 0); 381 382 /** @brief Gets the mouse-wheel motion delta, when handling mouse-wheel events EVENT_MOUSEWHEEL and 383 EVENT_MOUSEHWHEEL. 384 385 @param flags The mouse callback flags parameter. 386 387 For regular mice with a scroll-wheel, delta will be a multiple of 120. The value 120 corresponds to 388 a one notch rotation of the wheel or the threshold for action to be taken and one such action should 389 occur for each delta. Some high-precision mice with higher-resolution freely-rotating wheels may 390 generate smaller values. 391 392 For EVENT_MOUSEWHEEL positive and negative values mean forward and backward scrolling, 393 respectively. For EVENT_MOUSEHWHEEL, where available, positive and negative values mean right and 394 left scrolling, respectively. 395 396 With the C API, the macro CV_GET_WHEEL_DELTA(flags) can be used alternatively. 397 398 @note 399 400 Mouse-wheel events are currently supported only on Windows. 401 */ 402 CV_EXPORTS int getMouseWheelDelta(int flags); 403 404 /** @brief Creates a trackbar and attaches it to the specified window. 405 406 @param trackbarname Name of the created trackbar. 407 @param winname Name of the window that will be used as a parent of the created trackbar. 408 @param value Optional pointer to an integer variable whose value reflects the position of the 409 slider. Upon creation, the slider position is defined by this variable. 410 @param count Maximal position of the slider. The minimal position is always 0. 411 @param onChange Pointer to the function to be called every time the slider changes position. This 412 function should be prototyped as void Foo(int,void\*); , where the first parameter is the trackbar 413 position and the second parameter is the user data (see the next parameter). If the callback is 414 the NULL pointer, no callbacks are called, but only value is updated. 415 @param userdata User data that is passed as is to the callback. It can be used to handle trackbar 416 events without using global variables. 417 418 The function createTrackbar creates a trackbar (a slider or range control) with the specified name 419 and range, assigns a variable value to be a position synchronized with the trackbar and specifies 420 the callback function onChange to be called on the trackbar position change. The created trackbar is 421 displayed in the specified window winname. 422 423 @note 424 425 **[Qt Backend Only]** winname can be empty (or NULL) if the trackbar should be attached to the 426 control panel. 427 428 Clicking the label of each trackbar enables editing the trackbar values manually. 429 430 @note 431 432 - An example of using the trackbar functionality can be found at 433 opencv_source_code/samples/cpp/connected_components.cpp 434 */ 435 CV_EXPORTS int createTrackbar(const String& trackbarname, const String& winname, 436 int* value, int count, 437 TrackbarCallback onChange = 0, 438 void* userdata = 0); 439 440 /** @brief Returns the trackbar position. 441 442 @param trackbarname Name of the trackbar. 443 @param winname Name of the window that is the parent of the trackbar. 444 445 The function returns the current position of the specified trackbar. 446 447 @note 448 449 **[Qt Backend Only]** winname can be empty (or NULL) if the trackbar is attached to the control 450 panel. 451 452 */ 453 CV_EXPORTS_W int getTrackbarPos(const String& trackbarname, const String& winname); 454 455 /** @brief Sets the trackbar position. 456 457 @param trackbarname Name of the trackbar. 458 @param winname Name of the window that is the parent of trackbar. 459 @param pos New position. 460 461 The function sets the position of the specified trackbar in the specified window. 462 463 @note 464 465 **[Qt Backend Only]** winname can be empty (or NULL) if the trackbar is attached to the control 466 panel. 467 */ 468 CV_EXPORTS_W void setTrackbarPos(const String& trackbarname, const String& winname, int pos); 469 470 /** @brief Sets the trackbar maximum position. 471 472 @param trackbarname Name of the trackbar. 473 @param winname Name of the window that is the parent of trackbar. 474 @param maxval New maximum position. 475 476 The function sets the maximum position of the specified trackbar in the specified window. 477 478 @note 479 480 **[Qt Backend Only]** winname can be empty (or NULL) if the trackbar is attached to the control 481 panel. 482 */ 483 CV_EXPORTS_W void setTrackbarMax(const String& trackbarname, const String& winname, int maxval); 484 485 //! @addtogroup highgui_opengl OpenGL support 486 //! @{ 487 488 CV_EXPORTS void imshow(const String& winname, const ogl::Texture2D& tex); 489 490 /** @brief Sets a callback function to be called to draw on top of displayed image. 491 492 @param winname Name of the window. 493 @param onOpenGlDraw Pointer to the function to be called every frame. This function should be 494 prototyped as void Foo(void\*) . 495 @param userdata Pointer passed to the callback function. *(Optional)* 496 497 The function setOpenGlDrawCallback can be used to draw 3D data on the window. See the example of 498 callback function below: : 499 @code 500 void on_opengl(void* param) 501 { 502 glLoadIdentity(); 503 504 glTranslated(0.0, 0.0, -1.0); 505 506 glRotatef( 55, 1, 0, 0 ); 507 glRotatef( 45, 0, 1, 0 ); 508 glRotatef( 0, 0, 0, 1 ); 509 510 static const int coords[6][4][3] = { 511 { { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } }, 512 { { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 } }, 513 { { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } }, 514 { { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } }, 515 { { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } }, 516 { { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } } 517 }; 518 519 for (int i = 0; i < 6; ++i) { 520 glColor3ub( i*20, 100+i*10, i*42 ); 521 glBegin(GL_QUADS); 522 for (int j = 0; j < 4; ++j) { 523 glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], 0.2 * coords[i][j][2]); 524 } 525 glEnd(); 526 } 527 } 528 @endcode 529 */ 530 CV_EXPORTS void setOpenGlDrawCallback(const String& winname, OpenGlDrawCallback onOpenGlDraw, void* userdata = 0); 531 532 /** @brief Sets the specified window as current OpenGL context. 533 534 @param winname Window name 535 */ 536 CV_EXPORTS void setOpenGlContext(const String& winname); 537 538 /** @brief Force window to redraw its context and call draw callback ( setOpenGlDrawCallback ). 539 540 @param winname Window name 541 */ 542 CV_EXPORTS void updateWindow(const String& winname); 543 544 //! @} highgui_opengl 545 546 //! @addtogroup highgui_qt 547 //! @{ 548 // Only for Qt 549 550 struct QtFont 551 { 552 const char* nameFont; // Qt: nameFont 553 Scalar color; // Qt: ColorFont -> cvScalar(blue_component, green_component, red_component[, alpha_component]) 554 int font_face; // Qt: bool italic 555 const int* ascii; // font data and metrics 556 const int* greek; 557 const int* cyrillic; 558 float hscale, vscale; 559 float shear; // slope coefficient: 0 - normal, >0 - italic 560 int thickness; // Qt: weight 561 float dx; // horizontal interval between letters 562 int line_type; // Qt: PointSize 563 }; 564 565 /** @brief Creates the font to draw a text on an image. 566 567 @param nameFont Name of the font. The name should match the name of a system font (such as 568 *Times*). If the font is not found, a default one is used. 569 @param pointSize Size of the font. If not specified, equal zero or negative, the point size of the 570 font is set to a system-dependent default value. Generally, this is 12 points. 571 @param color Color of the font in BGRA where A = 255 is fully transparent. Use the macro CV _ RGB 572 for simplicity. 573 @param weight Font weight. The following operation flags are available: 574 - **CV_FONT_LIGHT** Weight of 25 575 - **CV_FONT_NORMAL** Weight of 50 576 - **CV_FONT_DEMIBOLD** Weight of 63 577 - **CV_FONT_BOLD** Weight of 75 578 - **CV_FONT_BLACK** Weight of 87 579 580 You can also specify a positive integer for better control. 581 @param style Font style. The following operation flags are available: 582 - **CV_STYLE_NORMAL** Normal font 583 - **CV_STYLE_ITALIC** Italic font 584 - **CV_STYLE_OBLIQUE** Oblique font 585 @param spacing Spacing between characters. It can be negative or positive. 586 587 The function fontQt creates a CvFont object. This CvFont is not compatible with putText . 588 589 A basic usage of this function is the following: : 590 @code 591 CvFont font = fontQt(''Times''); 592 addText( img1, ``Hello World !'', Point(50,50), font); 593 @endcode 594 */ 595 CV_EXPORTS QtFont fontQt(const String& nameFont, int pointSize = -1, 596 Scalar color = Scalar::all(0), int weight = QT_FONT_NORMAL, 597 int style = QT_STYLE_NORMAL, int spacing = 0); 598 599 /** @brief Creates the font to draw a text on an image. 600 601 @param img 8-bit 3-channel image where the text should be drawn. 602 @param text Text to write on an image. 603 @param org Point(x,y) where the text should start on an image. 604 @param font Font to use to draw a text. 605 606 The function addText draws *text* on an image *img* using a specific font *font* (see example fontQt 607 ) 608 */ 609 CV_EXPORTS void addText( const Mat& img, const String& text, Point org, const QtFont& font); 610 611 /** @brief Displays a text on a window image as an overlay for a specified duration. 612 613 @param winname Name of the window. 614 @param text Overlay text to write on a window image. 615 @param delayms The period (in milliseconds), during which the overlay text is displayed. If this 616 function is called before the previous overlay text timed out, the timer is restarted and the text 617 is updated. If this value is zero, the text never disappears. 618 619 The function displayOverlay displays useful information/tips on top of the window for a certain 620 amount of time *delayms*. The function does not modify the image, displayed in the window, that is, 621 after the specified delay the original content of the window is restored. 622 */ 623 CV_EXPORTS void displayOverlay(const String& winname, const String& text, int delayms = 0); 624 625 /** @brief Displays a text on the window statusbar during the specified period of time. 626 627 @param winname Name of the window. 628 @param text Text to write on the window statusbar. 629 @param delayms Duration (in milliseconds) to display the text. If this function is called before 630 the previous text timed out, the timer is restarted and the text is updated. If this value is 631 zero, the text never disappears. 632 633 The function displayOverlay displays useful information/tips on top of the window for a certain 634 amount of time *delayms* . This information is displayed on the window statusbar (the window must be 635 created with the CV_GUI_EXPANDED flags). 636 */ 637 CV_EXPORTS void displayStatusBar(const String& winname, const String& text, int delayms = 0); 638 639 /** @brief Saves parameters of the specified window. 640 641 @param windowName Name of the window. 642 643 The function saveWindowParameters saves size, location, flags, trackbars value, zoom and panning 644 location of the window window_name . 645 */ 646 CV_EXPORTS void saveWindowParameters(const String& windowName); 647 648 /** @brief Loads parameters of the specified window. 649 650 @param windowName Name of the window. 651 652 The function loadWindowParameters loads size, location, flags, trackbars value, zoom and panning 653 location of the window window_name . 654 */ 655 CV_EXPORTS void loadWindowParameters(const String& windowName); 656 657 CV_EXPORTS int startLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]); 658 659 CV_EXPORTS void stopLoop(); 660 661 /** @brief Attaches a button to the control panel. 662 663 @param bar_name 664 Name of the button. 665 @param on_change Pointer to the function to be called every time the button changes its state. 666 This function should be prototyped as void Foo(int state,\*void); . *state* is the current state 667 of the button. It could be -1 for a push button, 0 or 1 for a check/radio box button. 668 @param userdata Pointer passed to the callback function. 669 @param type Optional type of the button. 670 - **CV_PUSH_BUTTON** Push button 671 - **CV_CHECKBOX** Checkbox button 672 - **CV_RADIOBOX** Radiobox button. The radiobox on the same buttonbar (same line) are 673 exclusive, that is only one can be selected at a time. 674 @param initial_button_state Default state of the button. Use for checkbox and radiobox. Its 675 value could be 0 or 1. *(Optional)* 676 677 The function createButton attaches a button to the control panel. Each button is added to a 678 buttonbar to the right of the last button. A new buttonbar is created if nothing was attached to the 679 control panel before, or if the last element attached to the control panel was a trackbar. 680 681 See below various examples of the createButton function call: : 682 @code 683 createButton(NULL,callbackButton);//create a push button "button 0", that will call callbackButton. 684 createButton("button2",callbackButton,NULL,CV_CHECKBOX,0); 685 createButton("button3",callbackButton,&value); 686 createButton("button5",callbackButton1,NULL,CV_RADIOBOX); 687 createButton("button6",callbackButton2,NULL,CV_PUSH_BUTTON,1); 688 @endcode 689 */ 690 CV_EXPORTS int createButton( const String& bar_name, ButtonCallback on_change, 691 void* userdata = 0, int type = QT_PUSH_BUTTON, 692 bool initial_button_state = false); 693 694 //! @} highgui_qt 695 696 //! @} highgui 697 698 } // cv 699 700 #ifndef DISABLE_OPENCV_24_COMPATIBILITY 701 #include "opencv2/highgui/highgui_c.h" 702 #endif 703 704 #endif 705