1
Until the feature request for this feature gets done, if you need this functionality and can't wait, you can implement it yourself. You'll need the opencv source code, then you'll have to edit some opencv files and rebuild part of opencv. I followed the source code for moveWindow() as a model.
That's what I did:
add to opencv/sources/modules/highgui/source/window_w32.cpp this function (I added it just below the cvMoveWindow definition):
CV_IMPL void cvGetWindowRect( const char* name, int &x, int &y, int &width, int &height)
{
CV_FUNCNAME( "cvGetWindowRect" );
__BEGIN__;
CvWindow* window;
RECT rect;
if( !name )
CV_ERROR( CV_StsNullPtr, "NULL name" );
window = icvFindWindowByName(name);
if(!window)
EXIT;
GetWindowRect( window->frame, &rect );
x = rect.left;
y = rect.top;
width = rect.right - rect.left;
height = rect.bottom - rect.top;
__END__;
}
and add its declaration in opencv/sources/modules/highgui/include/opencv2/highgui_c.h :
CVAPI(void) cvGetWindowRect( const char* name, int &x, int &y, int &width, int &height);
This alone would allow you to use the cvGetWindowRect from C/C++ to get the window rect. But if you want to use the C++ interface or the python interface (as I do) you can edit two files more:
add to opencv/sources/modules/highgui/source/window.cpp this function:
void cv::getWindowRect( const String& winname, CV_OUT int &x, CV_OUT int &y, CV_OUT int &width, CV_OUT int &height)
{
cvGetWindowRect(winname.c_str(), x, y, width, height);
}
and add its declaration in opencv/sources/modules/highgui/include/opencv2/highgui.hpp :
CV_EXPORTS_W void getWindowRect( const String& winname, CV_OUT int &x, CV_OUT int &y, CV_OUT int &width, CV_OUT int &height);
Then you'll have to rebuild the opencv_highgui project (I do this for windows with Visual Studio 2015). If you need the python bindings then rebuild the opencv_python3 project too. The CV_EXPORTS_W and CV_OUT macros are needed to expose the function and recognize the output parameters when building the python bindings. From python you'll get a 4-tuple as return value, ->eg:
>>> cv2.getWindowRect("my window")
(1024, 0, 817, 639)
For the python bindings you'll have to copy the new cv2.cp35-win_amd64.pyd and opencv_highgui300.dll to the PythonEnv\Lib\site-packages.