直到
实现此功能的请求得以完成,如果您需要此功能并且不能等待,可以自行实现。 您需要 OpenCV 源代码,然后您需要编辑一些 OpenCV 文件并重新构建部分 OpenCV。
我以
moveWindow() 的源代码为模型进行了跟踪。
我所做的是:
在
opencv/sources/modules/highgui/source/window_w32.cpp中添加此函数(我将其添加在
cvMoveWindow 定义的下方)。
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__;
}
并将其声明添加到
opencv/sources/modules/highgui/include/opencv2/highgui_c.h 中:
CVAPI(void) cvGetWindowRect( const char* name, int &x, int &y, int &width, int &height);
仅这一步就足以让您在C/C++中使用cvGetWindowRect来获取窗口矩形。但是,如果您想使用C++接口或Python接口(就像我一样),您还可以编辑另外两个文件:
将以下函数添加到opencv/sources/modules/highgui/source/window.cpp中:
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);
}
并在
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);
然后你需要重新构建
opencv_highgui 项目(我在Windows上使用Visual Studio 2015进行此操作)。如果你需要Python绑定,那么也需要重新构建
opencv_python3 项目。在构建Python绑定时,需要使用CV_EXPORTS_W和CV_OUT宏来公开函数并识别输出参数。从Python中,你将得到一个4元组作为返回值,->例如:
>>> cv2.getWindowRect("my window")
(1024, 0, 817, 639)
对于Python绑定,您需要将新的
cv2.cp35-win_amd64.pyd和
opencv_highgui300.dll复制到
PythonEnv\Lib\site-packages目录下。
loadWindowParameters
函数很可能会加载由saveWindowParameters
函数保存到某个地方的参数。 - ChronoTriggerloadWindowParameters()
/saveWindowParameters()
пјҹжҲ‘жҲҗеҠҹең°дҪҝз”ЁдәҶOpenCVпјҢдҪҶжҳҜеҜ№иҝҷдәӣеҮҪж•°иҝҳдёҚеӨӘзҗҶи§ЈгҖӮ - AlexcvGetWindowHandle
,它可以返回窗口的平台特定句柄(HWND、GTK、Carbon等),然后从那里入手。 - nils