diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index fd7f227ca8..634f9ec35c 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -59,6 +59,7 @@ set(highgui_srcs set(highgui_hdrs src/precomp.hpp src/utils.hpp) +#YV set(lib_hdr_names highgui_c.h highgui.hpp) set(highgui_ext_hdrs) foreach(h ${lib_hdr_names}) @@ -73,7 +74,7 @@ if(WIN32) #SET(QT_USE_QTXML 1) INCLUDE(${QT_USE_FILE}) - SET(_MOC_HEADERS src/window_QT.h) + SET(_MOC_HEADERS src/window_QT.h ) QT4_WRAP_CPP(_MOC_OUTFILES ${_MOC_HEADERS}) set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} ${QT_LIBRARIES}) diff --git a/modules/highgui/include/opencv2/highgui/highgui.hpp b/modules/highgui/include/opencv2/highgui/highgui.hpp index 9c7feb3d8c..05fdfa9be0 100644 --- a/modules/highgui/include/opencv2/highgui/highgui.hpp +++ b/modules/highgui/include/opencv2/highgui/highgui.hpp @@ -56,6 +56,12 @@ namespace cv enum { WINDOW_AUTOSIZE=1 }; +//YV +//-----------New for QT +//CV_EXPORTS void information(const string& name, const string& text, int delayms); +//------------ + + CV_EXPORTS void namedWindow( const string& winname, int flags CV_DEFAULT(WINDOW_AUTOSIZE) ); CV_EXPORTS void destroyWindow( const string& winname ); CV_EXPORTS int startWindowThread(); diff --git a/modules/highgui/include/opencv2/highgui/highgui_c.h b/modules/highgui/include/opencv2/highgui/highgui_c.h index cb97bf12f5..e280d3b0a1 100644 --- a/modules/highgui/include/opencv2/highgui/highgui_c.h +++ b/modules/highgui/include/opencv2/highgui/highgui_c.h @@ -56,6 +56,11 @@ extern "C" { /****************************************************************************************\ * Basic GUI functions * \****************************************************************************************/ +//YV +//-----------New for QT +//CVAPI(void) cvInformation(const char* name, const char* text, int delayms); +//---------------------- + /* this function is used to set some external parameters in case of X Window */ CVAPI(int) cvInitSystem( int argc, char** argv ); @@ -76,10 +81,13 @@ enum CV_WINDOW_FULLSCREEN = 1 }; + /* Set and Get Property of the window */ CVAPI(void) cvSetWindowProperty(const char* name, int prop_id, double prop_value); CVAPI(double) cvGetWindowProperty(const char* name, int prop_id); +CVAPI(void) cvInformation(const char* name, const char* text, int delayms); + /* display image within window (highgui windows remember their content) */ CVAPI(void) cvShowImage( const char* name, const CvArr* image ); @@ -200,17 +208,8 @@ CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0 /* wait for key event infinitely (delay<=0) or for "delay" milliseconds */ CVAPI(int) cvWaitKey(int delay CV_DEFAULT(0)); -//YV -#if defined (HAVE_QT) - class CvWindow; - class ViewPort; - struct CvTrackbar; +void cvInformation(const char* name, const char* text, int delay); - CVAPI(int) cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char *argv[]); - CVAPI(void) cvStopLoop(); - CVAPI(void) cvInformation(const char* name, const char* text, int delay); - CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_window ); -#endif /****************************************************************************************\ * Working with Video Files and Cameras * diff --git a/modules/highgui/src/precomp.hpp b/modules/highgui/src/precomp.hpp index 47295ab551..5457530d80 100644 --- a/modules/highgui/src/precomp.hpp +++ b/modules/highgui/src/precomp.hpp @@ -171,6 +171,18 @@ void cvChangeMode_GTK(const char* name, double prop_value); void cvChangeMode_CARBON(const char* name, double prop_value); void cvChangeMode_QT(const char* name, double prop_value); +//#if defined (HAVE_QT) + //class CvWindow; + //class ViewPort; + //struct CvTrackbar; + + ////new functions available to the users + //#include "highgui_QT_extension.h" + ////new functions hidden to the users + //CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_window ); +//#endif + + /*namespace cv { diff --git a/modules/highgui/src/window.cpp b/modules/highgui/src/window.cpp index cf5aebd8b1..2e90646501 100644 --- a/modules/highgui/src/window.cpp +++ b/modules/highgui/src/window.cpp @@ -131,6 +131,13 @@ double getWindowProperty(const string& winname, int prop_id) return cvGetWindowProperty(winname.c_str(),prop_id); } +/* +void information(const string& name, const string& text, int delayms) +{ + cvInformation(name.c_str(),text.c_str(), delayms); +} +* */ + void imshow( const string& winname, const Mat& img ) { CvMat _img = img; diff --git a/modules/highgui/src/window_QT.cpp b/modules/highgui/src/window_QT.cpp index 5b9f288db7..bf2907fe82 100755 --- a/modules/highgui/src/window_QT.cpp +++ b/modules/highgui/src/window_QT.cpp @@ -53,29 +53,46 @@ QWaitCondition key_pressed; QMutex mutexKey; //end static and global - //end declaration void cvChangeMode_QT(const char* name, double prop_value) { - //CV_WINDOW_NORMAL or CV_WINDOW_FULLSCREEN - + QMetaObject::invokeMethod(&guiMainThread, + "toggleFullScreen", + Qt::AutoConnection, + Q_ARG(QString, QString(name)), + Q_ARG(double, prop_value)); } double cvGetMode_QT(const char* name) { - - return 0; + double result; + + QMetaObject::invokeMethod(&guiMainThread, + "isFullScreen", + Qt::AutoConnection, + Q_RETURN_ARG(double, result), + Q_ARG(QString, QString(name))); + return result; } +CV_IMPL void cvInformation(const char* name, const char* text, int delayms) +{ + + QMetaObject::invokeMethod(&guiMainThread, + "displayInfo", + Qt::AutoConnection, + //Qt::DirectConnection, + Q_ARG(QString, QString(name)), + Q_ARG(QString, QString(text)), + Q_ARG(int, delayms)); + +} + + CV_IMPL int cvWaitKey( int arg ) { - - CV_FUNCNAME( "cvWaitKey" ); - int result = -1; - __BEGIN__; - unsigned long delayms;//in milliseconds if (arg<=0) delayms = ULONG_MAX; @@ -124,21 +141,19 @@ CV_IMPL int cvWaitKey( int arg ) } guiMainThread._bTimeOut = false; } - - __END__; - + return result; } -CV_IMPL int cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]) +int cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]) { multiThreads = true; QFuture future = QtConcurrent::run(pt2Func,argc,argv); return guiMainThread.start(); } -CV_IMPL void cvStopLoop() +void cvStopLoop() { qApp->exit(); } @@ -146,12 +161,8 @@ CV_IMPL void cvStopLoop() CV_IMPL CvWindow* icvFindWindowByName( const char* arg ) { - - CV_FUNCNAME( "icvFindWindowByName" ); QPointer window = NULL; - - __BEGIN__; if( !arg ) CV_Error( CV_StsNullPtr, "NULL name string" ); @@ -168,19 +179,14 @@ CV_IMPL CvWindow* icvFindWindowByName( const char* arg ) } } - __END__; return window; } -CV_IMPL CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_window ) +CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_window ) { - CV_FUNCNAME( "icvFindTrackbarByName" ); - QPointer result = NULL; - __BEGIN__; - QPointer w = icvFindWindowByName( name_window ); if( !w ) @@ -200,16 +206,12 @@ CV_IMPL CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char } } - __END__; return result; } CV_IMPL int cvNamedWindow( const char* name, int flags ) { - CV_FUNCNAME( "cvNamedWindow" ); - __BEGIN__; - if (multiThreads) QMetaObject::invokeMethod(&guiMainThread, "createWindow", @@ -221,31 +223,13 @@ CV_IMPL int cvNamedWindow( const char* name, int flags ) Q_ARG(int, flags)); else guiMainThread.createWindow(QString(name),flags); - - __END__; + return 1;//Dummy value } -CV_IMPL void cvInformation(const char* name, const char* text, int delayms) -{ - CV_FUNCNAME( "cvInformation" ); - - __BEGIN__; - QMetaObject::invokeMethod(&guiMainThread, - "displayInfo", - Qt::AutoConnection, - Q_ARG(QString, QString(name)), - Q_ARG(QString, QString(text)), - Q_ARG(int, delayms)); - - __END__; -} CV_IMPL int icvInitSystem( int argc, char** argv ) { - CV_FUNCNAME( "icvInitSystem" ); - - __BEGIN__; static int wasInitialized = 0; @@ -258,15 +242,11 @@ CV_IMPL int icvInitSystem( int argc, char** argv ) qDebug()<<"init done"<windowTitle().toLatin1().data(); } CV_IMPL void cvMoveWindow( const char* name, int x, int y ) { - CV_FUNCNAME( "cvMoveWindow" ); - __BEGIN__; QMetaObject::invokeMethod(&guiMainThread, "moveWindow", @@ -334,17 +297,12 @@ CV_IMPL void cvMoveWindow( const char* name, int x, int y ) Q_ARG(int, x), Q_ARG(int, y) ); - - __END__; + } CV_IMPL void cvResizeWindow(const char* name, int width, int height ) { - CV_FUNCNAME( "cvResizeWindow" ); - - __BEGIN__; - QMetaObject::invokeMethod(&guiMainThread, "resizeWindow", //Qt::BlockingQueuedConnection, @@ -353,14 +311,12 @@ CV_IMPL void cvResizeWindow(const char* name, int width, int height ) Q_ARG(int, width), Q_ARG(int, height) ); - - __END__; } CV_IMPL int cvCreateTrackbar2( const char* trackbar_name, const char* window_name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata ) { - //TODO: implement the real one, not a wrapper + //TODO: implement the real one, not a wrapper return cvCreateTrackbar( trackbar_name, window_name, val, count, (CvTrackbarCallback)on_notify ); } @@ -371,9 +327,6 @@ CV_IMPL int cvStartWindowThread() CV_IMPL int cvCreateTrackbar( const char* trackbar_name, const char* window_name, int* value, int count, CvTrackbarCallback on_change) { - CV_FUNCNAME( "cvCreateTrackbar" ); - - __BEGIN__; if (multiThreads) QMetaObject::invokeMethod(&guiMainThread, @@ -388,75 +341,53 @@ CV_IMPL int cvCreateTrackbar( const char* trackbar_name, const char* window_name else guiMainThread.addSlider(QString(trackbar_name),QString(window_name),(void*)value,count,(void*)on_change); - __END__; - return 1;//demmy value + return 1;//demmy value } CV_IMPL int cvGetTrackbarPos( const char* trackbar_name, const char* window_name ) { - CV_FUNCNAME( "cvGetTrackbarPos" ); - int result = -1; - - __BEGIN__; - + QPointer t = icvFindTrackbarByName( trackbar_name, window_name ); if (t) result = t->slider->value(); - - __END__; + return result; } CV_IMPL void cvSetTrackbarPos( const char* trackbar_name, const char* window_name, int pos ) { - CV_FUNCNAME( "cvSetTrackbarPos" ); - - __BEGIN__; QPointer t = icvFindTrackbarByName( trackbar_name, window_name ); if (t) t->slider->setValue(pos); - - __END__; + } /* assign callback for mouse events */ CV_IMPL void cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse,void* param ) -{ - CV_FUNCNAME( "cvSetMouseCallback" ); - - __BEGIN__; - +{ QPointer w = icvFindWindowByName( window_name ); if (!w) CV_Error(CV_StsNullPtr, "NULL window handler" ); w->setMouseCallBack(on_mouse, param); - - __END__; + } CV_IMPL void cvShowImage( const char* name, const CvArr* arr ) { - CV_FUNCNAME( "cvShowImage" ); - __BEGIN__; - //objects were created in GUI thread, so not using invoke method here should be fine - guiMainThread.showImage(QString(name), (void*) arr); - - // QMetaObject::invokeMethod(&guiMainThread, - // "showImage", - // //Qt::BlockingQueuedConnection, - // Qt::AutoConnection, - // Q_ARG(QString, QString(name)), - // Q_ARG(void*, (void*)arr) - // ); - - __END__; + QMetaObject::invokeMethod(&guiMainThread, + "showImage", + //Qt::BlockingQueuedConnection, + Qt::DirectConnection, + Q_ARG(QString, QString(name)), + Q_ARG(void*, (void*)arr) + ); } @@ -465,6 +396,7 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr ) + //----------OBJECT---------------- GuiReceiver::GuiReceiver() : _bTimeOut(false) @@ -473,6 +405,35 @@ GuiReceiver::GuiReceiver() : _bTimeOut(false) qApp->setQuitOnLastWindowClosed ( false );//maybe the user would like to access this setting } +double GuiReceiver::isFullScreen(QString name) +{ + QPointer w = icvFindWindowByName( name.toLatin1().data() ); + + if (!w) + return -1; + + if (w->isFullScreen()) + return CV_WINDOW_FULLSCREEN; + else + return CV_WINDOW_NORMAL; +} + +//accept CV_WINDOW_NORMAL or CV_WINDOW_FULLSCREEN +void GuiReceiver::toggleFullScreen(QString name, double flags ) +{ + QPointer w = icvFindWindowByName( name.toLatin1().data() ); + + if (!w) + return; + + if (w->isFullScreen() && flags == CV_WINDOW_NORMAL) + w->showNormal(); + + if (!w->isFullScreen() && flags == CV_WINDOW_FULLSCREEN) + w->showFullScreen(); + +} + void GuiReceiver::createWindow( QString name, int flags ) { if (!qApp) diff --git a/modules/highgui/src/window_QT.h b/modules/highgui/src/window_QT.h index d8f582b4f3..ada693c35d 100644 --- a/modules/highgui/src/window_QT.h +++ b/modules/highgui/src/window_QT.h @@ -37,6 +37,9 @@ //the use of this software, even if advised of the possibility of such damage. //--------------------Google Code 2010 -- Yannick Verdie--------------------// +#ifndef __OPENCV_HIGHGUI_QT_H__ +#define __OPENCV_HIGHGUI_QT_H__ + #include "precomp.hpp" @@ -63,15 +66,15 @@ #include #include - - //Macro here #define CV_MODE_NORMAL 0 #define CV_MODE_OPENGL 1 //end macro -//Here declare everything -//need a .h to allow QT to use MOC (in order to use signal, slots, etc) +class CvWindow; +class ViewPort; +//class CvTrackbar; + class GuiReceiver : public QObject { @@ -95,6 +98,8 @@ public slots: void displayInfo( QString name, QString text, int delayms ); void refreshEvents(); void timeOut(); + void toggleFullScreen(QString name, double flags ); + double isFullScreen(QString name); }; class CvTrackbar : public QHBoxLayout @@ -263,3 +268,5 @@ static const QString str_Trackbar_css = QString("") + "border: 1px solid #aaa;" + "border-radius: 4px;" + "}"; + +#endif