试图关闭OpenCV窗口没有效果
Trying to close OpenCV window has no effect
我正在用OpenCV捕捉网络摄像头图像。这很好。但是,如果我想在按下按钮时关闭OpenCV,它不起作用(尝试了cvDestroyWindow("NameOfWindow")
和cvDestroyAllWindows()
)。窗口保持打开状态,应用程序仍在运行。
OpenCV在独立于主GUI的线程上初始化。
我在Mac上使用c++的Juce框架。但同样的问题也发生在Windows上,当OpenCV窗口有它自己的cvNamedWindow时,Qt和Windows Forms。
下面是VST插件编辑器类的基本代码:PluginEditor.cpp
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "PluginProcessor.h"
#include "PluginEditor.h"
//
TestAudioProcessorEditor::TestAudioProcessorEditor (TestAudioProcessor* ownerFilter)
: AudioProcessorEditor (ownerFilter)
{
// This is where our plugin's editor size is set.
setSize (500, 500);
// open the tracker
openTracker();
}
// code for opencv handling
TestAudioProcessorEditor::openTracker() {
// KEY LINE: Start the window thread
cvStartWindowThread();
// Create a window in which the captured images will be presented
cvNamedWindow( "Webcam", CV_WINDOW_AUTOSIZE );
cvWaitKey(0);
cvDestroyWindow( "Webcam" );
// window should disappear!
}
TestAudioProcessorEditor::~TestAudioProcessorEditor()
{
}
// paint stuff on the vst plugin surface
void TestAudioProcessorEditor::paint (Graphics& g) {
}
您可能缺少的部分是对cvStartWindowThread
函数的调用。
在Linux上,使用GTK HighGUI,这个例子再现了你的问题,直到我把cvStartWindowThread
的调用。
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <iostream>
using namespace std;
int main( int argc, char** argv )
{
// KEY LINE: Start the window thread
cvStartWindowThread();
// Open a window
cvNamedWindow("original", 0);
// Wait until a key gets pressed inside the window
cvWaitKey(0);
// Close the window
cvDestroyWindow("original");
// Verify that the window is closed
cout<<"The window should be closed now. (Press ENTER to continue.)"<<endl;
string line;
getline(cin, line);
cout<<"Exiting..."<<endl;
}
如果cvStartWindowThread
没有帮助,尝试在cvDestroy
调用之后对cvWaitKey
进行额外调用。
要运行该示例,请使用GCC编译它:
g++ destroy_window.cpp -o destroy_window -lopencv_core -lopencv_highgui
相关文章:
- unique_ptr:在分配之前调用 reset 有什么效果
- [longjmp/setjmp]c++ 相同的代码窗口有异常 Linux 没有错误并且运行良好
- 有没有办法像动画一样移动控制台窗口?
- 有没有办法一次运行 3 个创建窗口函数?
- 我在窗口中有一个fltk Fl_Choice下拉菜单,但只能通过鼠标使用
- ESP32_BLE_Arduino库中的扫描窗口、间隔和扫描时间之间有什么区别
- 如何在 direct2d 中使用随其窗口重新缩放的效果绘制图像
- 控制台窗口未在开发C++中打开?即使也有 getch() ?
- 有没有办法拿一个opencv显示窗口并将其保存到GUI窗口?
- 鼠标输入和键输入有什么区别(在前台获取窗口)
- 有没有办法知道父窗口的类型(基于框架或对话框)?
- 有没有办法为使用 Boost 生成的进程创建新的控制台窗口
- 破坏滤纸的“确定”、“取消”和“帮助”窗口的效果
- 控制台窗口有图标,但 OpenGL/GLUT 窗口没有。为什么?
- 试图关闭OpenCV窗口没有效果
- MFC -消息框显示,主窗口有一个取消按钮.消息框处于活动状态时防止取消
- 如何在Qt Creator 5.7中制作一个只有一个窗口的c++ GUI程序,但每次点击都会使窗口有其他元素-如设置向导
- 从ui-thread显示窗口有时会阻塞主ui-thread
- Mac的通知窗口.有或没有Qt
- Windows无边界OpenGL窗口有奇怪的选项卡问题