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"
44 #include "opencv2/core/opengl_interop.hpp"
46 // in later times, use this file as a dispatcher to implementations like cvcap.cpp
48 CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_value)
52 //change between fullscreen or not.
53 case CV_WND_PROP_FULLSCREEN:
55 if (!name || (prop_value!=CV_WINDOW_NORMAL && prop_value!=CV_WINDOW_FULLSCREEN))//bad argument
59 cvSetModeWindow_QT(name,prop_value);
60 #elif defined(HAVE_WIN32UI)
61 cvSetModeWindow_W32(name,prop_value);
62 #elif defined (HAVE_GTK)
63 cvSetModeWindow_GTK(name,prop_value);
64 #elif defined (HAVE_CARBON)
65 cvSetModeWindow_CARBON(name,prop_value);
66 #elif defined (HAVE_COCOA)
67 cvSetModeWindow_COCOA(name,prop_value);
71 case CV_WND_PROP_AUTOSIZE:
73 cvSetPropWindow_QT(name,prop_value);
77 case CV_WND_PROP_ASPECTRATIO:
79 cvSetRatioWindow_QT(name,prop_value);
87 /* return -1 if error */
88 CV_IMPL double cvGetWindowProperty(const char* name, int prop_id)
95 case CV_WND_PROP_FULLSCREEN:
98 return cvGetModeWindow_QT(name);
99 #elif defined(HAVE_WIN32UI)
100 return cvGetModeWindow_W32(name);
101 #elif defined (HAVE_GTK)
102 return cvGetModeWindow_GTK(name);
103 #elif defined (HAVE_CARBON)
104 return cvGetModeWindow_CARBON(name);
105 #elif defined (HAVE_COCOA)
106 return cvGetModeWindow_COCOA(name);
112 case CV_WND_PROP_AUTOSIZE:
114 #if defined (HAVE_QT)
115 return cvGetPropWindow_QT(name);
116 #elif defined(HAVE_WIN32UI)
117 return cvGetPropWindowAutoSize_W32(name);
118 #elif defined (HAVE_GTK)
119 return cvGetPropWindowAutoSize_GTK(name);
125 case CV_WND_PROP_ASPECTRATIO:
127 #if defined (HAVE_QT)
128 return cvGetRatioWindow_QT(name);
129 #elif defined(HAVE_WIN32UI)
130 return cvGetRatioWindow_W32(name);
131 #elif defined (HAVE_GTK)
132 return cvGetRatioWindow_GTK(name);
138 case CV_WND_PROP_OPENGL:
140 #if defined (HAVE_QT)
141 return cvGetOpenGlProp_QT(name);
142 #elif defined(HAVE_WIN32UI)
143 return cvGetOpenGlProp_W32(name);
144 #elif defined (HAVE_GTK)
145 return cvGetOpenGlProp_GTK(name);
156 void cv::namedWindow( const string& winname, int flags )
158 cvNamedWindow( winname.c_str(), flags );
161 void cv::destroyWindow( const string& winname )
163 cvDestroyWindow( winname.c_str() );
166 void cv::destroyAllWindows()
168 cvDestroyAllWindows();
171 void cv::resizeWindow( const string& winname, int width, int height )
173 cvResizeWindow( winname.c_str(), width, height );
176 void cv::moveWindow( const string& winname, int x, int y )
178 cvMoveWindow( winname.c_str(), x, y );
181 void cv::setWindowProperty(const string& winname, int prop_id, double prop_value)
183 cvSetWindowProperty( winname.c_str(), prop_id, prop_value);
186 double cv::getWindowProperty(const string& winname, int prop_id)
188 return cvGetWindowProperty(winname.c_str(), prop_id);
191 int cv::waitKey(int delay)
193 return cvWaitKey(delay);
196 int cv::createTrackbar(const string& trackbarName, const string& winName,
197 int* value, int count, TrackbarCallback callback,
200 return cvCreateTrackbar2(trackbarName.c_str(), winName.c_str(),
201 value, count, callback, userdata);
204 void cv::setTrackbarPos( const string& trackbarName, const string& winName, int value )
206 cvSetTrackbarPos(trackbarName.c_str(), winName.c_str(), value );
209 int cv::getTrackbarPos( const string& trackbarName, const string& winName )
211 return cvGetTrackbarPos(trackbarName.c_str(), winName.c_str());
214 void cv::setMouseCallback( const string& windowName, MouseCallback onMouse, void* param)
216 cvSetMouseCallback(windowName.c_str(), onMouse, param);
219 int cv::startWindowThread()
221 return cvStartWindowThread();
226 void cv::setOpenGlDrawCallback(const string& name, OpenGlDrawCallback callback, void* userdata)
228 cvSetOpenGlDrawCallback(name.c_str(), callback, userdata);
231 void cv::setOpenGlContext(const string& windowName)
233 cvSetOpenGlContext(windowName.c_str());
236 void cv::updateWindow(const string& windowName)
238 cvUpdateWindow(windowName.c_str());
244 std::map<std::string, cv::ogl::Texture2D> wndTexs;
245 std::map<std::string, cv::ogl::Texture2D> ownWndTexs;
246 std::map<std::string, cv::ogl::Buffer> ownWndBufs;
248 void glDrawTextureCallback(void* userdata)
250 cv::ogl::Texture2D* texObj = static_cast<cv::ogl::Texture2D*>(userdata);
252 cv::ogl::render(*texObj);
255 #endif // HAVE_OPENGL
257 void cv::imshow( const string& winname, InputArray _img )
259 const Size size = _img.size();
261 CV_Assert(size.width>0 && size.height>0);
263 Mat img = _img.getMat();
265 cvShowImage(winname.c_str(), &c_img);
268 const double useGl = getWindowProperty(winname, WND_PROP_OPENGL);
269 CV_Assert(size.width>0 && size.height>0);
273 Mat img = _img.getMat();
275 cvShowImage(winname.c_str(), &c_img);
279 const double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
283 resizeWindow(winname, size.width, size.height);
286 setOpenGlContext(winname);
288 if (_img.kind() == _InputArray::OPENGL_TEXTURE)
290 cv::ogl::Texture2D& tex = wndTexs[winname];
292 tex = _img.getOGlTexture2D();
294 tex.setAutoRelease(false);
296 setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex);
300 cv::ogl::Texture2D& tex = ownWndTexs[winname];
302 if (_img.kind() == _InputArray::GPU_MAT)
304 cv::ogl::Buffer& buf = ownWndBufs[winname];
306 buf.setAutoRelease(false);
309 tex.setAutoRelease(false);
316 tex.setAutoRelease(false);
318 setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex);
321 updateWindow(winname);
326 void cv::pointCloudShow(const string&, const GlCamera&, const GlArrays&)
328 CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it");
331 void cv::pointCloudShow(const string&, const GlCamera&, InputArray, InputArray)
333 CV_Error(CV_StsNotImplemented, "This function in deprecated, do not use it");
340 CV_IMPL void cvSetOpenGlDrawCallback(const char*, CvOpenGlDrawCallback, void*)
342 CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
345 CV_IMPL void cvSetOpenGlContext(const char*)
347 CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
350 CV_IMPL void cvUpdateWindow(const char*)
352 CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
355 #endif // !HAVE_OPENGL
357 #if defined (HAVE_QT)
359 CvFont cv::fontQt(const string& nameFont, int pointSize, Scalar color, int weight, int style, int /*spacing*/)
361 return cvFontQt(nameFont.c_str(), pointSize,color,weight, style);
364 void cv::addText( const Mat& img, const string& text, Point org, CvFont font)
367 cvAddText( &_img, text.c_str(), org,&font);
370 void cv::displayStatusBar(const string& name, const string& text, int delayms)
372 cvDisplayStatusBar(name.c_str(),text.c_str(), delayms);
375 void cv::displayOverlay(const string& name, const string& text, int delayms)
377 cvDisplayOverlay(name.c_str(),text.c_str(), delayms);
380 int cv::startLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[])
382 return cvStartLoop(pt2Func, argc, argv);
390 void cv::saveWindowParameters(const string& windowName)
392 cvSaveWindowParameters(windowName.c_str());
395 void cv::loadWindowParameters(const string& windowName)
397 cvLoadWindowParameters(windowName.c_str());
400 int cv::createButton(const string& button_name, ButtonCallback on_change, void* userdata, int button_type , bool initial_button_state )
402 return cvCreateButton(button_name.c_str(), on_change, userdata, button_type , initial_button_state );
407 CvFont cv::fontQt(const string&, int, Scalar, int, int, int)
409 CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
413 void cv::addText( const Mat&, const string&, Point, CvFont)
415 CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
418 void cv::displayStatusBar(const string&, const string&, int)
420 CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
423 void cv::displayOverlay(const string&, const string&, int )
425 CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
428 int cv::startLoop(int (*)(int argc, char *argv[]), int , char**)
430 CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
436 CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
439 void cv::saveWindowParameters(const string&)
441 CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
444 void cv::loadWindowParameters(const string&)
446 CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
449 int cv::createButton(const string&, ButtonCallback, void*, int , bool )
451 CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
457 #if defined(HAVE_WIN32UI) // see window_w32.cpp
458 #elif defined (HAVE_GTK) // see window_gtk.cpp
459 #elif defined (HAVE_COCOA) // see window_carbon.cpp
460 #elif defined (HAVE_CARBON)
461 #elif defined (HAVE_QT) //YV see window_QT.cpp
465 // No windowing system present at compile time ;-(
467 // We will build place holders that don't break the API but give an error
468 // at runtime. This way people can choose to replace an installed HighGUI
469 // version with a more capable one without a need to recompile dependent
470 // applications or libraries.
473 #define CV_NO_GUI_ERROR(funcname) \
474 cvError( CV_StsError, funcname, \
475 "The function is not implemented. " \
476 "Rebuild the library with Windows, GTK+ 2.x or Carbon support. "\
477 "If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script", \
481 CV_IMPL int cvNamedWindow( const char*, int )
483 CV_NO_GUI_ERROR("cvNamedWindow");
487 CV_IMPL void cvDestroyWindow( const char* )
489 CV_NO_GUI_ERROR( "cvDestroyWindow" );
493 cvDestroyAllWindows( void )
495 CV_NO_GUI_ERROR( "cvDestroyAllWindows" );
499 cvShowImage( const char*, const CvArr* )
501 CV_NO_GUI_ERROR( "cvShowImage" );
504 CV_IMPL void cvResizeWindow( const char*, int, int )
506 CV_NO_GUI_ERROR( "cvResizeWindow" );
509 CV_IMPL void cvMoveWindow( const char*, int, int )
511 CV_NO_GUI_ERROR( "cvMoveWindow" );
515 cvCreateTrackbar( const char*, const char*,
516 int*, int, CvTrackbarCallback )
518 CV_NO_GUI_ERROR( "cvCreateTrackbar" );
523 cvCreateTrackbar2( const char* /*trackbar_name*/, const char* /*window_name*/,
524 int* /*val*/, int /*count*/, CvTrackbarCallback2 /*on_notify2*/,
527 CV_NO_GUI_ERROR( "cvCreateTrackbar2" );
532 cvSetMouseCallback( const char*, CvMouseCallback, void* )
534 CV_NO_GUI_ERROR( "cvSetMouseCallback" );
537 CV_IMPL int cvGetTrackbarPos( const char*, const char* )
539 CV_NO_GUI_ERROR( "cvGetTrackbarPos" );
543 CV_IMPL void cvSetTrackbarPos( const char*, const char*, int )
545 CV_NO_GUI_ERROR( "cvSetTrackbarPos" );
548 CV_IMPL void* cvGetWindowHandle( const char* )
550 CV_NO_GUI_ERROR( "cvGetWindowHandle" );
554 CV_IMPL const char* cvGetWindowName( void* )
556 CV_NO_GUI_ERROR( "cvGetWindowName" );
560 CV_IMPL int cvWaitKey( int )
562 CV_NO_GUI_ERROR( "cvWaitKey" );
566 CV_IMPL int cvInitSystem( int , char** )
569 CV_NO_GUI_ERROR( "cvInitSystem" );
573 CV_IMPL int cvStartWindowThread()
576 CV_NO_GUI_ERROR( "cvStartWindowThread" );
580 //-------- Qt ---------
581 CV_IMPL void cvAddText( const CvArr*, const char*, CvPoint , CvFont* )
583 CV_NO_GUI_ERROR("cvAddText");
586 CV_IMPL void cvDisplayStatusBar(const char* , const char* , int )
588 CV_NO_GUI_ERROR("cvDisplayStatusBar");
591 CV_IMPL void cvDisplayOverlay(const char* , const char* , int )
593 CV_NO_GUI_ERROR("cvNamedWindow");
596 CV_IMPL int cvStartLoop(int (*)(int argc, char *argv[]), int , char* argv[])
599 CV_NO_GUI_ERROR("cvStartLoop");
603 CV_IMPL void cvStopLoop()
605 CV_NO_GUI_ERROR("cvStopLoop");
608 CV_IMPL void cvSaveWindowParameters(const char* )
610 CV_NO_GUI_ERROR("cvSaveWindowParameters");
613 // CV_IMPL void cvLoadWindowParameterss(const char* name)
615 // CV_NO_GUI_ERROR("cvLoadWindowParameters");
618 CV_IMPL int cvCreateButton(const char*, void (*)(int, void*), void*, int, int)
620 CV_NO_GUI_ERROR("cvCreateButton");