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.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);
69
cvSetModeWindow_WinRT(name, prop_value);
74
case CV_WND_PROP_AUTOSIZE:
76
cvSetPropWindow_QT(name,prop_value);
80
case CV_WND_PROP_ASPECTRATIO:
82
cvSetRatioWindow_QT(name,prop_value);
90
/* return -1 if error */
91
CV_IMPL double cvGetWindowProperty(const char* name, int prop_id)
98
case CV_WND_PROP_FULLSCREEN:
100
#if defined (HAVE_QT)
101
return cvGetModeWindow_QT(name);
102
#elif defined(HAVE_WIN32UI)
103
return cvGetModeWindow_W32(name);
104
#elif defined (HAVE_GTK)
105
return cvGetModeWindow_GTK(name);
106
#elif defined (HAVE_CARBON)
107
return cvGetModeWindow_CARBON(name);
108
#elif defined (HAVE_COCOA)
109
return cvGetModeWindow_COCOA(name);
110
#elif defined (WINRT)
111
return cvGetModeWindow_WinRT(name);
117
case CV_WND_PROP_AUTOSIZE:
119
#if defined (HAVE_QT)
120
return cvGetPropWindow_QT(name);
121
#elif defined(HAVE_WIN32UI)
122
return cvGetPropWindowAutoSize_W32(name);
123
#elif defined (HAVE_GTK)
124
return cvGetPropWindowAutoSize_GTK(name);
130
case CV_WND_PROP_ASPECTRATIO:
132
#if defined (HAVE_QT)
133
return cvGetRatioWindow_QT(name);
134
#elif defined(HAVE_WIN32UI)
135
return cvGetRatioWindow_W32(name);
136
#elif defined (HAVE_GTK)
137
return cvGetRatioWindow_GTK(name);
143
case CV_WND_PROP_OPENGL:
145
#if defined (HAVE_QT)
146
return cvGetOpenGlProp_QT(name);
147
#elif defined(HAVE_WIN32UI)
148
return cvGetOpenGlProp_W32(name);
149
#elif defined (HAVE_GTK)
150
return cvGetOpenGlProp_GTK(name);
161
void cv::namedWindow( const String& winname, int flags )
163
cvNamedWindow( winname.c_str(), flags );
166
void cv::destroyWindow( const String& winname )
168
cvDestroyWindow( winname.c_str() );
171
void cv::destroyAllWindows()
173
cvDestroyAllWindows();
176
void cv::resizeWindow( const String& winname, int width, int height )
178
cvResizeWindow( winname.c_str(), width, height );
181
void cv::moveWindow( const String& winname, int x, int y )
183
cvMoveWindow( winname.c_str(), x, y );
186
void cv::setWindowProperty(const String& winname, int prop_id, double prop_value)
188
cvSetWindowProperty( winname.c_str(), prop_id, prop_value);
191
double cv::getWindowProperty(const String& winname, int prop_id)
193
return cvGetWindowProperty(winname.c_str(), prop_id);
196
int cv::waitKey(int delay)
198
return cvWaitKey(delay);
201
int cv::createTrackbar(const String& trackbarName, const String& winName,
202
int* value, int count, TrackbarCallback callback,
205
return cvCreateTrackbar2(trackbarName.c_str(), winName.c_str(),
206
value, count, callback, userdata);
209
void cv::setTrackbarPos( const String& trackbarName, const String& winName, int value )
211
cvSetTrackbarPos(trackbarName.c_str(), winName.c_str(), value );
214
void cv::setTrackbarMax(const String& trackbarName, const String& winName, int maxval)
216
cvSetTrackbarMax(trackbarName.c_str(), winName.c_str(), maxval);
219
void cv::setTrackbarMin(const String& trackbarName, const String& winName, int minval)
221
cvSetTrackbarMin(trackbarName.c_str(), winName.c_str(), minval);
224
int cv::getTrackbarPos( const String& trackbarName, const String& winName )
226
return cvGetTrackbarPos(trackbarName.c_str(), winName.c_str());
229
void cv::setMouseCallback( const String& windowName, MouseCallback onMouse, void* param)
231
cvSetMouseCallback(windowName.c_str(), onMouse, param);
234
int cv::getMouseWheelDelta( int flags )
236
return CV_GET_WHEEL_DELTA(flags);
239
int cv::startWindowThread()
241
return cvStartWindowThread();
246
void cv::setOpenGlDrawCallback(const String& name, OpenGlDrawCallback callback, void* userdata)
248
cvSetOpenGlDrawCallback(name.c_str(), callback, userdata);
251
void cv::setOpenGlContext(const String& windowName)
253
cvSetOpenGlContext(windowName.c_str());
256
void cv::updateWindow(const String& windowName)
258
cvUpdateWindow(windowName.c_str());
264
std::map<cv::String, cv::ogl::Texture2D> wndTexs;
265
std::map<cv::String, cv::ogl::Texture2D> ownWndTexs;
266
std::map<cv::String, cv::ogl::Buffer> ownWndBufs;
268
void glDrawTextureCallback(void* userdata)
270
cv::ogl::Texture2D* texObj = static_cast<cv::ogl::Texture2D*>(userdata);
272
cv::ogl::render(*texObj);
275
#endif // HAVE_OPENGL
277
void cv::imshow( const String& winname, InputArray _img )
279
const Size size = _img.size();
281
CV_Assert(size.width>0 && size.height>0);
283
Mat img = _img.getMat();
285
cvShowImage(winname.c_str(), &c_img);
288
const double useGl = getWindowProperty(winname, WND_PROP_OPENGL);
289
CV_Assert(size.width>0 && size.height>0);
293
Mat img = _img.getMat();
295
cvShowImage(winname.c_str(), &c_img);
299
const double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
303
resizeWindow(winname, size.width, size.height);
306
setOpenGlContext(winname);
308
cv::ogl::Texture2D& tex = ownWndTexs[winname];
310
if (_img.kind() == _InputArray::CUDA_GPU_MAT)
312
cv::ogl::Buffer& buf = ownWndBufs[winname];
314
buf.setAutoRelease(false);
317
tex.setAutoRelease(false);
324
tex.setAutoRelease(false);
326
setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex);
328
updateWindow(winname);
333
void cv::imshow(const String& winname, const ogl::Texture2D& _tex)
338
CV_Error(cv::Error::OpenGlNotSupported, "The library is compiled without OpenGL support");
340
const double useGl = getWindowProperty(winname, WND_PROP_OPENGL);
344
CV_Error(cv::Error::OpenGlNotSupported, "The window was created without OpenGL context");
348
const double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
352
Size size = _tex.size();
353
resizeWindow(winname, size.width, size.height);
356
setOpenGlContext(winname);
358
cv::ogl::Texture2D& tex = wndTexs[winname];
362
tex.setAutoRelease(false);
364
setOpenGlDrawCallback(winname, glDrawTextureCallback, &tex);
366
updateWindow(winname);
375
CV_IMPL void cvSetOpenGlDrawCallback(const char*, CvOpenGlDrawCallback, void*)
377
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
380
CV_IMPL void cvSetOpenGlContext(const char*)
382
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
385
CV_IMPL void cvUpdateWindow(const char*)
387
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
390
#endif // !HAVE_OPENGL
392
#if defined (HAVE_QT)
394
cv::QtFont cv::fontQt(const String& nameFont, int pointSize, Scalar color, int weight, int style, int /*spacing*/)
396
CvFont f = cvFontQt(nameFont.c_str(), pointSize,color,weight, style);
397
void* pf = &f; // to suppress strict-aliasing
398
return *(cv::QtFont*)pf;
401
void cv::addText( const Mat& img, const String& text, Point org, const QtFont& font)
404
cvAddText( &_img, text.c_str(), org, (CvFont*)&font);
407
void cv::displayStatusBar(const String& name, const String& text, int delayms)
409
cvDisplayStatusBar(name.c_str(),text.c_str(), delayms);
412
void cv::displayOverlay(const String& name, const String& text, int delayms)
414
cvDisplayOverlay(name.c_str(),text.c_str(), delayms);
417
int cv::startLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[])
419
return cvStartLoop(pt2Func, argc, argv);
427
void cv::saveWindowParameters(const String& windowName)
429
cvSaveWindowParameters(windowName.c_str());
432
void cv::loadWindowParameters(const String& windowName)
434
cvLoadWindowParameters(windowName.c_str());
437
int cv::createButton(const String& button_name, ButtonCallback on_change, void* userdata, int button_type , bool initial_button_state )
439
return cvCreateButton(button_name.c_str(), on_change, userdata, button_type , initial_button_state );
444
cv::QtFont cv::fontQt(const String&, int, Scalar, int, int, int)
446
CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
450
void cv::addText( const Mat&, const String&, Point, const QtFont&)
452
CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
455
void cv::displayStatusBar(const String&, const String&, int)
457
CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
460
void cv::displayOverlay(const String&, const String&, int )
462
CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
465
int cv::startLoop(int (*)(int argc, char *argv[]), int , char**)
467
CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
473
CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
476
void cv::saveWindowParameters(const String&)
478
CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
481
void cv::loadWindowParameters(const String&)
483
CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
486
int cv::createButton(const String&, ButtonCallback, void*, int , bool )
488
CV_Error(CV_StsNotImplemented, "The library is compiled without QT support");
494
#if defined (HAVE_WIN32UI) // see window_w32.cpp
495
#elif defined (HAVE_GTK) // see window_gtk.cpp
496
#elif defined (HAVE_COCOA) // see window_carbon.cpp
497
#elif defined (HAVE_CARBON)
498
#elif defined (HAVE_QT) // see window_QT.cpp
499
#elif defined (WINRT) && !defined (WINRT_8_0) // see window_winrt.cpp
503
// No windowing system present at compile time ;-(
505
// We will build place holders that don't break the API but give an error
506
// at runtime. This way people can choose to replace an installed HighGUI
507
// version with a more capable one without a need to recompile dependent
508
// applications or libraries.
510
void cv::setWindowTitle(const String&, const String&)
512
CV_Error(Error::StsNotImplemented, "The function is not implemented. "
513
"Rebuild the library with Windows, GTK+ 2.x or Carbon support. "
514
"If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script");
517
#define CV_NO_GUI_ERROR(funcname) \
518
cvError( CV_StsError, funcname, \
519
"The function is not implemented. " \
520
"Rebuild the library with Windows, GTK+ 2.x or Carbon support. "\
521
"If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script", \
525
CV_IMPL int cvNamedWindow( const char*, int )
527
CV_NO_GUI_ERROR("cvNamedWindow");
531
CV_IMPL void cvDestroyWindow( const char* )
533
CV_NO_GUI_ERROR( "cvDestroyWindow" );
537
cvDestroyAllWindows( void )
539
CV_NO_GUI_ERROR( "cvDestroyAllWindows" );
543
cvShowImage( const char*, const CvArr* )
545
CV_NO_GUI_ERROR( "cvShowImage" );
548
CV_IMPL void cvResizeWindow( const char*, int, int )
550
CV_NO_GUI_ERROR( "cvResizeWindow" );
553
CV_IMPL void cvMoveWindow( const char*, int, int )
555
CV_NO_GUI_ERROR( "cvMoveWindow" );
559
cvCreateTrackbar( const char*, const char*,
560
int*, int, CvTrackbarCallback )
562
CV_NO_GUI_ERROR( "cvCreateTrackbar" );
567
cvCreateTrackbar2( const char* /*trackbar_name*/, const char* /*window_name*/,
568
int* /*val*/, int /*count*/, CvTrackbarCallback2 /*on_notify2*/,
571
CV_NO_GUI_ERROR( "cvCreateTrackbar2" );
576
cvSetMouseCallback( const char*, CvMouseCallback, void* )
578
CV_NO_GUI_ERROR( "cvSetMouseCallback" );
581
CV_IMPL int cvGetTrackbarPos( const char*, const char* )
583
CV_NO_GUI_ERROR( "cvGetTrackbarPos" );
587
CV_IMPL void cvSetTrackbarPos( const char*, const char*, int )
589
CV_NO_GUI_ERROR( "cvSetTrackbarPos" );
592
CV_IMPL void cvSetTrackbarMax(const char*, const char*, int)
594
CV_NO_GUI_ERROR( "cvSetTrackbarMax" );
597
CV_IMPL void cvSetTrackbarMin(const char*, const char*, int)
599
CV_NO_GUI_ERROR( "cvSetTrackbarMin" );
602
CV_IMPL void* cvGetWindowHandle( const char* )
604
CV_NO_GUI_ERROR( "cvGetWindowHandle" );
608
CV_IMPL const char* cvGetWindowName( void* )
610
CV_NO_GUI_ERROR( "cvGetWindowName" );
614
CV_IMPL int cvWaitKey( int )
616
CV_NO_GUI_ERROR( "cvWaitKey" );
620
CV_IMPL int cvInitSystem( int , char** )
623
CV_NO_GUI_ERROR( "cvInitSystem" );
627
CV_IMPL int cvStartWindowThread()
630
CV_NO_GUI_ERROR( "cvStartWindowThread" );
634
//-------- Qt ---------
635
CV_IMPL void cvAddText( const CvArr*, const char*, CvPoint , CvFont* )
637
CV_NO_GUI_ERROR("cvAddText");
640
CV_IMPL void cvDisplayStatusBar(const char* , const char* , int )
642
CV_NO_GUI_ERROR("cvDisplayStatusBar");
645
CV_IMPL void cvDisplayOverlay(const char* , const char* , int )
647
CV_NO_GUI_ERROR("cvNamedWindow");
650
CV_IMPL int cvStartLoop(int (*)(int argc, char *argv[]), int , char* argv[])
653
CV_NO_GUI_ERROR("cvStartLoop");
657
CV_IMPL void cvStopLoop()
659
CV_NO_GUI_ERROR("cvStopLoop");
662
CV_IMPL void cvSaveWindowParameters(const char* )
664
CV_NO_GUI_ERROR("cvSaveWindowParameters");
667
// CV_IMPL void cvLoadWindowParameterss(const char* name)
669
// CV_NO_GUI_ERROR("cvLoadWindowParameters");
672
CV_IMPL int cvCreateButton(const char*, void (*)(int, void*), void*, int, int)
674
CV_NO_GUI_ERROR("cvCreateButton");