highgui.hpp 29 KB

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