修改CV函数 for moveWindow()

20 篇文章 0 订阅

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值