1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
42 #include "precomp.hpp"
43 #include "backend.hpp"
45 #include "opencv2/core/opengl.hpp"
46 #include "opencv2/core/utils/logger.hpp"
48 // in later times, use this file as a dispatcher to implementations like cvcap.cpp
52 using namespace cv::highgui_backend;
56 Mutex& getWindowMutex()
58 static Mutex* g_window_mutex = new Mutex();
59 return *g_window_mutex;
64 typedef std::map<std::string, highgui_backend::UIWindowBase::Ptr> WindowsMap_t;
65 static WindowsMap_t& getWindowsMap()
67 static WindowsMap_t g_windowsMap;
71 static std::shared_ptr<UIWindow> findWindow_(const std::string& name)
73 cv::AutoLock lock(cv::getWindowMutex());
74 auto& windowsMap = getWindowsMap();
75 auto i = windowsMap.find(name);
76 if (i != windowsMap.end())
78 const auto& ui_base = i->second;
81 if (!ui_base->isActive())
84 return std::shared_ptr<UIWindow>();
86 auto window = std::dynamic_pointer_cast<UIWindow>(ui_base);
90 return std::shared_ptr<UIWindow>();
93 static void cleanupTrackbarCallbacksWithData_(); // forward declaration
95 static void cleanupClosedWindows_()
97 cv::AutoLock lock(cv::getWindowMutex());
98 auto& windowsMap = getWindowsMap();
99 for (auto it = windowsMap.begin(); it != windowsMap.end();)
101 const auto& ui_base = it->second;
102 bool erase = (!ui_base || !ui_base->isActive());
105 it = windowsMap.erase(it);
113 cleanupTrackbarCallbacksWithData_();
116 // Just to support deprecated API, to be removed
117 struct TrackbarCallbackWithData
119 std::weak_ptr<UITrackbar> trackbar_;
121 TrackbarCallback callback_;
124 TrackbarCallbackWithData(int* data, TrackbarCallback callback, void* userdata)
126 , callback_(callback), userdata_(userdata)
128 // trackbar_ is initialized separatelly
131 ~TrackbarCallbackWithData()
133 CV_LOG_DEBUG(NULL, "UI/Trackbar: Cleanup deprecated TrackbarCallbackWithData");
136 void onChange(int pos)
141 callback_(pos, userdata_);
144 static void onChangeCallback(int pos, void* userdata)
146 TrackbarCallbackWithData* thiz = (TrackbarCallbackWithData*)userdata;
148 return thiz->onChange(pos);
152 typedef std::vector< std::shared_ptr<TrackbarCallbackWithData> > TrackbarCallbacksWithData_t;
153 static TrackbarCallbacksWithData_t& getTrackbarCallbacksWithData()
155 static TrackbarCallbacksWithData_t g_trackbarCallbacksWithData;
156 return g_trackbarCallbacksWithData;
159 static void cleanupTrackbarCallbacksWithData_()
161 cv::AutoLock lock(cv::getWindowMutex());
162 auto& callbacks = getTrackbarCallbacksWithData();
163 for (auto it = callbacks.begin(); it != callbacks.end();)
165 const auto& cb = *it;
166 bool erase = (!cb || cb->trackbar_.expired());
169 it = callbacks.erase(it);
178 }} // namespace cv::impl
180 using namespace cv::impl;
182 #if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
183 static void deprecateNotFoundNoOpBehavior()
185 CV_LOG_ONCE_WARNING(NULL, "This no-op behavior is deprecated. Future versions of OpenCV will trigger exception in this case");
187 #define CV_NOT_FOUND_DEPRECATION deprecateNotFoundNoOpBehavior()
190 CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_value)
196 auto window = findWindow_(name);
199 /*bool res = */window->setProperty(prop_id, prop_value);
204 #if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
205 auto backend = getCurrentUIBackend();
208 CV_LOG_WARNING(NULL, "Can't find window with name: '" << name << "'. Do nothing");
209 CV_NOT_FOUND_DEPRECATION;
213 CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
219 //change between fullscreen or not.
220 case CV_WND_PROP_FULLSCREEN:
222 if (prop_value != CV_WINDOW_NORMAL && prop_value != CV_WINDOW_FULLSCREEN) // bad argument
225 #if defined (HAVE_QT)
226 cvSetModeWindow_QT(name,prop_value);
227 #elif defined(HAVE_WIN32UI)
228 cvSetModeWindow_W32(name,prop_value);
229 #elif defined (HAVE_GTK)
230 cvSetModeWindow_GTK(name,prop_value);
231 #elif defined (HAVE_COCOA)
232 cvSetModeWindow_COCOA(name,prop_value);
233 #elif defined (WINRT)
234 cvSetModeWindow_WinRT(name, prop_value);
239 case CV_WND_PROP_AUTOSIZE:
240 #if defined (HAVE_QT)
241 cvSetPropWindow_QT(name,prop_value);
245 case CV_WND_PROP_ASPECTRATIO:
246 #if defined (HAVE_QT)
247 cvSetRatioWindow_QT(name,prop_value);
251 case cv::WND_PROP_TOPMOST:
252 #if defined (HAVE_QT)
254 #elif defined(HAVE_WIN32UI)
255 cvSetPropTopmost_W32(name, (prop_value != 0 ? true : false));
256 #elif defined(HAVE_COCOA)
257 cvSetPropTopmost_COCOA(name, (prop_value != 0 ? true : false));
261 case cv::WND_PROP_VSYNC:
262 #if defined (HAVE_QT)
264 #elif defined (HAVE_WIN32UI)
265 cvSetPropVsync_W32(name, (prop_value != 0));
267 // not implemented yet for other toolkits
276 /* return -1 if error */
277 CV_IMPL double cvGetWindowProperty(const char* name, int prop_id)
283 auto window = findWindow_(name);
286 double v = window->getProperty(prop_id);
293 #if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
294 auto backend = getCurrentUIBackend();
297 CV_LOG_WARNING(NULL, "Can't find window with name: '" << name << "'. Do nothing");
298 CV_NOT_FOUND_DEPRECATION;
302 CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
308 case CV_WND_PROP_FULLSCREEN:
310 #if defined (HAVE_QT)
311 return cvGetModeWindow_QT(name);
312 #elif defined(HAVE_WIN32UI)
313 return cvGetModeWindow_W32(name);
314 #elif defined (HAVE_GTK)
315 return cvGetModeWindow_GTK(name);
316 #elif defined (HAVE_COCOA)
317 return cvGetModeWindow_COCOA(name);
318 #elif defined (WINRT)
319 return cvGetModeWindow_WinRT(name);
325 case CV_WND_PROP_AUTOSIZE:
327 #if defined (HAVE_QT)
328 return cvGetPropWindow_QT(name);
329 #elif defined(HAVE_WIN32UI)
330 return cvGetPropWindowAutoSize_W32(name);
331 #elif defined (HAVE_GTK)
332 return cvGetPropWindowAutoSize_GTK(name);
338 case CV_WND_PROP_ASPECTRATIO:
340 #if defined (HAVE_QT)
341 return cvGetRatioWindow_QT(name);
342 #elif defined(HAVE_WIN32UI)
343 return cvGetRatioWindow_W32(name);
344 #elif defined (HAVE_GTK)
345 return cvGetRatioWindow_GTK(name);
351 case CV_WND_PROP_OPENGL:
353 #if defined (HAVE_QT)
354 return cvGetOpenGlProp_QT(name);
355 #elif defined(HAVE_WIN32UI)
356 return cvGetOpenGlProp_W32(name);
357 #elif defined (HAVE_GTK)
358 return cvGetOpenGlProp_GTK(name);
364 case CV_WND_PROP_VISIBLE:
365 #if defined (HAVE_QT)
366 return cvGetPropVisible_QT(name);
367 #elif defined(HAVE_WIN32UI)
368 return cvGetPropVisible_W32(name);
374 case cv::WND_PROP_TOPMOST:
375 #if defined (HAVE_QT)
377 #elif defined(HAVE_WIN32UI)
378 return cvGetPropTopmost_W32(name);
379 #elif defined(HAVE_COCOA)
380 return cvGetPropTopmost_COCOA(name);
386 case cv::WND_PROP_VSYNC:
387 #if defined (HAVE_QT)
389 #elif defined (HAVE_WIN32UI)
390 return cvGetPropVsync_W32(name);
402 cv::Rect cvGetWindowImageRect(const char* name)
408 auto window = findWindow_(name);
411 return window->getImageRect();
415 #if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
416 auto backend = getCurrentUIBackend();
419 CV_LOG_WARNING(NULL, "Can't find window with name: '" << name << "'. Do nothing");
420 CV_NOT_FOUND_DEPRECATION;
424 CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
426 return Rect(-1, -1, -1, -1);
429 #if defined (HAVE_QT)
430 return cvGetWindowRect_QT(name);
431 #elif defined(HAVE_WIN32UI)
432 return cvGetWindowRect_W32(name);
433 #elif defined (HAVE_GTK)
434 return cvGetWindowRect_GTK(name);
435 #elif defined (HAVE_COCOA)
436 return cvGetWindowRect_COCOA(name);
438 return Rect(-1, -1, -1, -1);
444 cv::Rect cv::getWindowImageRect(const String& winname)
447 return cvGetWindowImageRect(winname.c_str());
450 void cv::namedWindow( const String& winname, int flags )
453 CV_Assert(!winname.empty());
456 cv::AutoLock lock(cv::getWindowMutex());
457 cleanupClosedWindows_();
458 auto& windowsMap = getWindowsMap();
459 auto i = windowsMap.find(winname);
460 if (i != windowsMap.end())
462 auto ui_base = i->second;
465 auto window = std::dynamic_pointer_cast<UIWindow>(ui_base);
468 CV_LOG_ERROR(NULL, "OpenCV/UI: Can't create window: '" << winname << "'");
473 auto backend = getCurrentUIBackend();
476 auto window = backend->createWindow(winname, flags);
479 CV_LOG_ERROR(NULL, "OpenCV/UI: Can't create window: '" << winname << "'");
482 windowsMap.emplace(winname, window);
487 cvNamedWindow( winname.c_str(), flags );
490 void cv::destroyWindow( const String& winname )
495 auto window = findWindow_(winname);
499 cleanupClosedWindows_();
504 cvDestroyWindow( winname.c_str() );
507 void cv::destroyAllWindows()
512 cv::AutoLock lock(cv::getWindowMutex());
513 auto backend = getCurrentUIBackend();
516 backend->destroyAllWindows();
517 cleanupClosedWindows_();
522 cvDestroyAllWindows();
525 void cv::resizeWindow( const String& winname, int width, int height )
530 auto window = findWindow_(winname);
533 return window->resize(width, height);
537 #if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
538 auto backend = getCurrentUIBackend();
541 CV_LOG_WARNING(NULL, "Can't find window with name: '" << winname << "'. Do nothing");
542 CV_NOT_FOUND_DEPRECATION;
546 CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
550 cvResizeWindow( winname.c_str(), width, height );
554 void cv::resizeWindow(const String& winname, const cv::Size& size)
557 cvResizeWindow(winname.c_str(), size.width, size.height);
560 void cv::moveWindow( const String& winname, int x, int y )
565 auto window = findWindow_(winname);
568 return window->move(x, y);
572 #if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
573 auto backend = getCurrentUIBackend();
576 CV_LOG_WARNING(NULL, "Can't find window with name: '" << winname << "'. Do nothing");
577 CV_NOT_FOUND_DEPRECATION;
581 CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
585 cvMoveWindow( winname.c_str(), x, y );
589 void cv::setWindowProperty(const String& winname, int prop_id, double prop_value)
592 cvSetWindowProperty( winname.c_str(), prop_id, prop_value);
595 double cv::getWindowProperty(const String& winname, int prop_id)
598 return cvGetWindowProperty(winname.c_str(), prop_id);
601 int cv::waitKeyEx(int delay)
606 cv::AutoLock lock(cv::getWindowMutex());
607 auto backend = getCurrentUIBackend();
610 return backend->waitKeyEx(delay);
614 return cvWaitKey(delay);
617 int cv::waitKey(int delay)
620 int code = waitKeyEx(delay);
622 static int use_legacy = -1;
625 use_legacy = getenv("OPENCV_LEGACY_WAITKEY") != NULL ? 1 : 0;
630 return (code != -1) ? (code & 0xff) : -1;
633 #if defined(HAVE_QT) || (defined (WINRT) && !defined (WINRT_8_0)) || \
634 !defined(HAVE_WIN32UI) && (defined(HAVE_GTK) || defined(HAVE_COCOA))
635 // pollKey() fallback implementation
641 cv::AutoLock lock(cv::getWindowMutex());
642 auto backend = getCurrentUIBackend();
645 return backend->pollKey();
649 // fallback. please implement a proper polling function
652 #elif defined(HAVE_WIN32UI)
653 // pollKey() implemented in window_w32.cpp
656 int cv::createTrackbar(const String& trackbarName, const String& winName,
657 int* value, int count, TrackbarCallback callback,
662 CV_LOG_IF_WARNING(NULL, value, "UI/Trackbar(" << trackbarName << "@" << winName << "): Using 'value' pointer is unsafe and deprecated. Use NULL as value pointer. "
663 "To fetch trackbar value setup callback.");
666 cv::AutoLock lock(cv::getWindowMutex());
667 auto window = findWindow_(winName);
672 auto cb = std::make_shared<TrackbarCallbackWithData>(value, callback, userdata);
673 auto trackbar = window->createTrackbar(trackbarName, count, TrackbarCallbackWithData::onChangeCallback, cb.get());
676 CV_LOG_ERROR(NULL, "OpenCV/UI: Can't create trackbar: '" << trackbarName << "'@'" << winName << "'");
679 cb->trackbar_ = trackbar;
680 getTrackbarCallbacksWithData().emplace_back(cb);
681 getWindowsMap().emplace(trackbar->getID(), trackbar);
682 trackbar->setPos(*value);
687 auto trackbar = window->createTrackbar(trackbarName, count, callback, userdata);
690 CV_LOG_ERROR(NULL, "OpenCV/UI: Can't create trackbar: '" << trackbarName << "'@'" << winName << "'");
693 getWindowsMap().emplace(trackbar->getID(), trackbar);
699 #if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
700 auto backend = getCurrentUIBackend();
703 CV_LOG_WARNING(NULL, "Can't find window with name: '" << winName << "'. Do nothing");
704 CV_NOT_FOUND_DEPRECATION;
708 CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
712 return cvCreateTrackbar2(trackbarName.c_str(), winName.c_str(),
713 value, count, callback, userdata);
717 void cv::setTrackbarPos( const String& trackbarName, const String& winName, int value )
722 cv::AutoLock lock(cv::getWindowMutex());
723 auto window = findWindow_(winName);
726 auto trackbar = window->findTrackbar(trackbarName);
728 return trackbar->setPos(value);
732 #if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
733 auto backend = getCurrentUIBackend();
736 CV_LOG_WARNING(NULL, "Can't find window with name: '" << winName << "'. Do nothing");
737 CV_NOT_FOUND_DEPRECATION;
741 CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
745 cvSetTrackbarPos(trackbarName.c_str(), winName.c_str(), value );
749 void cv::setTrackbarMax(const String& trackbarName, const String& winName, int maxval)
754 cv::AutoLock lock(cv::getWindowMutex());
755 auto window = findWindow_(winName);
758 auto trackbar = window->findTrackbar(trackbarName);
760 Range old_range = trackbar->getRange();
761 Range range(std::min(old_range.start, maxval), maxval);
762 return trackbar->setRange(range);
766 #if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
767 auto backend = getCurrentUIBackend();
770 CV_LOG_WARNING(NULL, "Can't find window with name: '" << winName << "'. Do nothing");
771 CV_NOT_FOUND_DEPRECATION;
775 CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
779 cvSetTrackbarMax(trackbarName.c_str(), winName.c_str(), maxval);
783 void cv::setTrackbarMin(const String& trackbarName, const String& winName, int minval)
788 cv::AutoLock lock(cv::getWindowMutex());
789 auto window = findWindow_(winName);
792 auto trackbar = window->findTrackbar(trackbarName);
794 Range old_range = trackbar->getRange();
795 Range range(minval, std::max(minval, old_range.end));
796 return trackbar->setRange(range);
800 #if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
801 auto backend = getCurrentUIBackend();
804 CV_LOG_WARNING(NULL, "Can't find window with name: '" << winName << "'. Do nothing");
805 CV_NOT_FOUND_DEPRECATION;
809 CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
813 cvSetTrackbarMin(trackbarName.c_str(), winName.c_str(), minval);
817 int cv::getTrackbarPos( const String& trackbarName, const String& winName )
822 cv::AutoLock lock(cv::getWindowMutex());
823 auto window = findWindow_(winName);
826 auto trackbar = window->findTrackbar(trackbarName);
828 return trackbar->getPos();
832 #if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
833 auto backend = getCurrentUIBackend();
836 CV_LOG_WARNING(NULL, "Can't find window with name: '" << winName << "'. Do nothing");
837 CV_NOT_FOUND_DEPRECATION;
841 CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
845 return cvGetTrackbarPos(trackbarName.c_str(), winName.c_str());
849 void cv::setMouseCallback( const String& windowName, MouseCallback onMouse, void* param)
854 cv::AutoLock lock(cv::getWindowMutex());
855 auto window = findWindow_(windowName);
858 return window->setMouseCallback(onMouse, param);
862 #if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
863 auto backend = getCurrentUIBackend();
866 CV_LOG_WARNING(NULL, "Can't find window with name: '" << windowName << "'. Do nothing");
867 CV_NOT_FOUND_DEPRECATION;
871 CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
875 cvSetMouseCallback(windowName.c_str(), onMouse, param);
879 int cv::getMouseWheelDelta( int flags )
882 return CV_GET_WHEEL_DELTA(flags);
885 int cv::startWindowThread()
888 return cvStartWindowThread();
893 void cv::setOpenGlDrawCallback(const String& name, OpenGlDrawCallback callback, void* userdata)
896 cvSetOpenGlDrawCallback(name.c_str(), callback, userdata);
899 void cv::setOpenGlContext(const String& windowName)
902 cvSetOpenGlContext(windowName.c_str());
905 void cv::updateWindow(const String& windowName)
908 cvUpdateWindow(windowName.c_str());
914 std::map<cv::String, cv::ogl::Texture2D> wndTexs;
915 std::map<cv::String, cv::ogl::Texture2D> ownWndTexs;
916 std::map<cv::String, cv::ogl::Buffer> ownWndBufs;
918 void glDrawTextureCallback(void* userdata)
920 cv::ogl::Texture2D* texObj = static_cast<cv::ogl::Texture2D*>(userdata);
922 cv::ogl::render(*texObj);
925 #endif // HAVE_OPENGL
927 void cv::imshow( const String& winname, InputArray _img )
932 cv::AutoLock lock(cv::getWindowMutex());
933 cleanupClosedWindows_();
934 auto& windowsMap = getWindowsMap();
935 auto i = windowsMap.find(winname);
936 if (i != windowsMap.end())
938 auto ui_base = i->second;
941 auto window = std::dynamic_pointer_cast<UIWindow>(ui_base);
944 CV_LOG_ERROR(NULL, "OpenCV/UI: invalid window name: '" << winname << "'");
946 return window->imshow(_img);
949 auto backend = getCurrentUIBackend();
952 auto window = backend->createWindow(winname, WINDOW_NORMAL);
955 CV_LOG_ERROR(NULL, "OpenCV/UI: Can't create window: '" << winname << "'");
958 windowsMap.emplace(winname, window);
959 return window->imshow(_img);
963 const Size size = _img.size();
965 CV_Assert(size.width>0 && size.height>0);
967 Mat img = _img.getMat();
968 CvMat c_img = cvMat(img);
969 cvShowImage(winname.c_str(), &c_img);
972 const double useGl = getWindowProperty(winname, WND_PROP_OPENGL);
973 CV_Assert(size.width>0 && size.height>0);
977 Mat img = _img.getMat();
978 CvMat c_img = cvMat(img);
979 cvShowImage(winname.c_str(), &c_img);
983 const double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
987 resizeWindow(winname, size.width, size.height);
990 setOpenGlContext(winname);
992 cv::ogl::Texture2D& tex = ownWndTexs[winname];
994 if (_img.kind() == _InputArray::CUDA_GPU_MAT)
996 cv::ogl::Buffer& buf = ownWndBufs[winname];
998 buf.setAutoRelease(false);
1001 tex.setAutoRelease(false);
1008 tex.setAutoRelease(false);
1010 setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex);
1012 updateWindow(winname);
1017 void cv::imshow(const String& winname, const ogl::Texture2D& _tex)
1019 CV_TRACE_FUNCTION();
1023 CV_Error(cv::Error::OpenGlNotSupported, "The library is compiled without OpenGL support");
1025 const double useGl = getWindowProperty(winname, WND_PROP_OPENGL);
1029 CV_Error(cv::Error::OpenGlNotSupported, "The window was created without OpenGL context");
1033 const double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
1037 Size size = _tex.size();
1038 resizeWindow(winname, size.width, size.height);
1041 setOpenGlContext(winname);
1043 cv::ogl::Texture2D& tex = wndTexs[winname];
1047 tex.setAutoRelease(false);
1049 setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex);
1051 updateWindow(winname);
1060 CV_IMPL void cvSetOpenGlDrawCallback(const char*, CvOpenGlDrawCallback, void*)
1062 CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
1065 CV_IMPL void cvSetOpenGlContext(const char*)
1067 CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
1070 CV_IMPL void cvUpdateWindow(const char*)
1072 CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
1075 #endif // !HAVE_OPENGL
1077 #if defined (HAVE_QT)
1079 cv::QtFont cv::fontQt(const String& nameFont, int pointSize, Scalar color, int weight, int style, int spacing)
1081 CvFont f = cvFontQt(nameFont.c_str(), pointSize, cvScalar(color), weight, style, spacing);
1082 void* pf = &f; // to suppress strict-aliasing
1083 return *(cv::QtFont*)pf;
1086 void cv::addText( const Mat& img, const String& text, Point org, const QtFont& font)
1088 CvMat _img = cvMat(img);
1089 cvAddText( &_img, text.c_str(), cvPoint(org), (CvFont*)&font);
1092 void cv::addText( const Mat& img, const String& text, Point org, const String& nameFont,
1093 int pointSize, Scalar color, int weight, int style, int spacing)
1095 CvFont f = cvFontQt(nameFont.c_str(), pointSize, cvScalar(color), weight, style, spacing);
1096 CvMat _img = cvMat(img);
1097 cvAddText( &_img, text.c_str(), cvPoint(org), &f);
1100 void cv::displayStatusBar(const String& name, const String& text, int delayms)
1102 cvDisplayStatusBar(name.c_str(),text.c_str(), delayms);
1105 void cv::displayOverlay(const String& name, const String& text, int delayms)
1107 cvDisplayOverlay(name.c_str(),text.c_str(), delayms);
1110 int cv::startLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[])
1112 return cvStartLoop(pt2Func, argc, argv);
1120 void cv::saveWindowParameters(const String& windowName)
1122 cvSaveWindowParameters(windowName.c_str());
1125 void cv::loadWindowParameters(const String& windowName)
1127 cvLoadWindowParameters(windowName.c_str());
1130 int cv::createButton(const String& button_name, ButtonCallback on_change, void* userdata, int button_type , bool initial_button_state )
1132 return cvCreateButton(button_name.c_str(), on_change, userdata, button_type , initial_button_state );
1137 static const char* NO_QT_ERR_MSG = "The library is compiled without QT support";
1139 cv::QtFont cv::fontQt(const String&, int, Scalar, int, int, int)
1141 CV_Error(CV_StsNotImplemented, NO_QT_ERR_MSG);
1144 void cv::addText( const Mat&, const String&, Point, const QtFont&)
1146 CV_Error(CV_StsNotImplemented, NO_QT_ERR_MSG);
1149 void cv::addText(const Mat&, const String&, Point, const String&, int, Scalar, int, int, int)
1151 CV_Error(CV_StsNotImplemented, NO_QT_ERR_MSG);
1154 void cv::displayStatusBar(const String&, const String&, int)
1156 CV_Error(CV_StsNotImplemented, NO_QT_ERR_MSG);
1159 void cv::displayOverlay(const String&, const String&, int )
1161 CV_Error(CV_StsNotImplemented, NO_QT_ERR_MSG);
1164 int cv::startLoop(int (*)(int argc, char *argv[]), int , char**)
1166 CV_Error(CV_StsNotImplemented, NO_QT_ERR_MSG);
1171 CV_Error(CV_StsNotImplemented, NO_QT_ERR_MSG);
1174 void cv::saveWindowParameters(const String&)
1176 CV_Error(CV_StsNotImplemented, NO_QT_ERR_MSG);
1179 void cv::loadWindowParameters(const String&)
1181 CV_Error(CV_StsNotImplemented, NO_QT_ERR_MSG);
1184 int cv::createButton(const String&, ButtonCallback, void*, int , bool )
1186 CV_Error(CV_StsNotImplemented, NO_QT_ERR_MSG);
1191 #if defined (HAVE_WIN32UI) // see window_w32.cpp
1192 #elif defined (HAVE_GTK) // see window_gtk.cpp
1193 #elif defined (HAVE_COCOA) // see window_cocoa.mm
1194 #elif defined (HAVE_QT) // see window_QT.cpp
1195 #elif defined (WINRT) && !defined (WINRT_8_0) // see window_winrt.cpp
1199 // No windowing system present at compile time ;-(
1201 // We will build place holders that don't break the API but give an error
1202 // at runtime. This way people can choose to replace an installed HighGUI
1203 // version with a more capable one without a need to recompile dependent
1204 // applications or libraries.
1206 void cv::setWindowTitle(const String&, const String&)
1208 CV_Error(Error::StsNotImplemented, "The function is not implemented. "
1209 "Rebuild the library with Windows, GTK+ 2.x or Cocoa support. "
1210 "If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script");
1213 #define CV_NO_GUI_ERROR(funcname) \
1214 cv::error(cv::Error::StsError, \
1215 "The function is not implemented. " \
1216 "Rebuild the library with Windows, GTK+ 2.x or Cocoa support. "\
1217 "If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script", \
1218 funcname, __FILE__, __LINE__)
1221 CV_IMPL int cvNamedWindow( const char*, int )
1223 CV_NO_GUI_ERROR("cvNamedWindow");
1226 CV_IMPL void cvDestroyWindow( const char* )
1228 CV_NO_GUI_ERROR( "cvDestroyWindow" );
1232 cvDestroyAllWindows( void )
1234 CV_NO_GUI_ERROR( "cvDestroyAllWindows" );
1238 cvShowImage( const char*, const CvArr* )
1240 CV_NO_GUI_ERROR( "cvShowImage" );
1243 CV_IMPL void cvResizeWindow( const char*, int, int )
1245 CV_NO_GUI_ERROR( "cvResizeWindow" );
1248 CV_IMPL void cvMoveWindow( const char*, int, int )
1250 CV_NO_GUI_ERROR( "cvMoveWindow" );
1254 cvCreateTrackbar( const char*, const char*,
1255 int*, int, CvTrackbarCallback )
1257 CV_NO_GUI_ERROR( "cvCreateTrackbar" );
1261 cvCreateTrackbar2( const char* /*trackbar_name*/, const char* /*window_name*/,
1262 int* /*val*/, int /*count*/, CvTrackbarCallback2 /*on_notify2*/,
1263 void* /*userdata*/ )
1265 CV_NO_GUI_ERROR( "cvCreateTrackbar2" );
1269 cvSetMouseCallback( const char*, CvMouseCallback, void* )
1271 CV_NO_GUI_ERROR( "cvSetMouseCallback" );
1274 CV_IMPL int cvGetTrackbarPos( const char*, const char* )
1276 CV_NO_GUI_ERROR( "cvGetTrackbarPos" );
1279 CV_IMPL void cvSetTrackbarPos( const char*, const char*, int )
1281 CV_NO_GUI_ERROR( "cvSetTrackbarPos" );
1284 CV_IMPL void cvSetTrackbarMax(const char*, const char*, int)
1286 CV_NO_GUI_ERROR( "cvSetTrackbarMax" );
1289 CV_IMPL void cvSetTrackbarMin(const char*, const char*, int)
1291 CV_NO_GUI_ERROR( "cvSetTrackbarMin" );
1294 CV_IMPL void* cvGetWindowHandle( const char* )
1296 CV_NO_GUI_ERROR( "cvGetWindowHandle" );
1299 CV_IMPL const char* cvGetWindowName( void* )
1301 CV_NO_GUI_ERROR( "cvGetWindowName" );
1304 CV_IMPL int cvWaitKey( int )
1306 CV_NO_GUI_ERROR( "cvWaitKey" );
1309 CV_IMPL int cvInitSystem( int , char** )
1312 CV_NO_GUI_ERROR( "cvInitSystem" );
1315 CV_IMPL int cvStartWindowThread()
1318 CV_NO_GUI_ERROR( "cvStartWindowThread" );
1321 //-------- Qt ---------
1322 CV_IMPL void cvAddText( const CvArr*, const char*, CvPoint , CvFont* )
1324 CV_NO_GUI_ERROR("cvAddText");
1327 CV_IMPL void cvDisplayStatusBar(const char* , const char* , int )
1329 CV_NO_GUI_ERROR("cvDisplayStatusBar");
1332 CV_IMPL void cvDisplayOverlay(const char* , const char* , int )
1334 CV_NO_GUI_ERROR("cvNamedWindow");
1337 CV_IMPL int cvStartLoop(int (*)(int argc, char *argv[]), int , char* argv[])
1340 CV_NO_GUI_ERROR("cvStartLoop");
1343 CV_IMPL void cvStopLoop()
1345 CV_NO_GUI_ERROR("cvStopLoop");
1348 CV_IMPL void cvSaveWindowParameters(const char* )
1350 CV_NO_GUI_ERROR("cvSaveWindowParameters");
1353 // CV_IMPL void cvLoadWindowParameterss(const char* name)
1355 // CV_NO_GUI_ERROR("cvLoadWindowParameters");
1358 CV_IMPL int cvCreateButton(const char*, void (*)(int, void*), void*, int, int)
1360 CV_NO_GUI_ERROR("cvCreateButton");
1365 CV_NO_GUI_ERROR("cv::pollKey()");