如何检查是否关闭了OpenCV的窗口 [英] How to check if an opencv window is closed

查看:920
本文介绍了如何检查是否关闭了OpenCV的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何检查如果OpenCV的窗口已被关闭?

How do you check if an opencv window has been closed?

我想这样做:

cvNamedWindow("main", 1);

while(!cvWindowIsClosed("main"))
{
    cvShowImage("main", myImage);   
}

但这些是没有这样的cvWindowIsClosed(...)的功能!

but these is no such cvWindowIsClosed(...) function!

推荐答案

什么你正在尝试做的可以用的 cvGetWindowHandle()

What you are trying to do can be achieved with cvGetWindowHandle():

该函数返回cvGetWindowHandle的本地窗口句柄(HWND在Win32和的GtkWidget的情况下,GTK +的情况下)。 [Qt的后端只有]具体QT-细节:该函数返回cvGetWindowHandle的本地窗口句柄从Qt的QWidget的类继承

The function cvGetWindowHandle returns the native window handle (HWND in case of Win32 and GtkWidget in case of GTK+). [Qt Backend Only] qt-specific details: The function cvGetWindowHandle returns the native window handle inheriting from the Qt class QWidget.

我们的想法是,以获得窗口的句柄,然后使用特定平台的API函数,以检查是否该手柄仍然有效。

The idea is to get the handle of the window and then use specific platform API functions to check if that handle is still valid.

编辑:

或者你可以使用tradicional cvWaitKey() 方法

Or you could use the tradicional cvWaitKey() approach:

char exit_key_press = 0;
while (exit_key_press != 'q') // or key != ESC
{
   // retrieve frame

   // display frame

   exit_key_press = cvWaitKey(10);
}

这篇关于如何检查是否关闭了OpenCV的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆