【发布时间】:2011-08-21 17:45:41
【问题描述】:
我正在使用 OpenCV 捕获网络摄像头图像。这很好用。但是如果我想在按下按钮时关闭 OpenCV,它就不起作用(尝试了 cvDestroyWindow("NameOfWindow") 和 cvDestroyAllWindows())。窗口保持打开状态,应用程序仍在运行。
OpenCV 是在与主 GUI 不同的线程上初始化的。
我在我的 Mac 上使用带有 C++ 的 Juce 框架。但是同样的问题也发生在带有 Qt 和 Windows 窗体的 Windows 上,当 OpenCV 窗口有它自己的 cvNamedWindow 时。
这里是VST插件编辑器类的基本代码:
插件编辑器.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) {
}
【问题讨论】:
-
当
cvDestroyAllWindows();被一个简单的按钮按下触发时,它会不会? -
您是否在产生窗口的同一线程中调用
cvDestroy(即称为cvNamedWindow)? -
@Dan Cecile 是的,我试过了,但它不起作用。
-
@Jacob 我有一个线程来存储和调用我的 opencv 内容。这是个问题吗?
-
@sn3ek:您必须向运行 OpenCV 的线程发送消息,并让该线程调用
cvDestroy。 (例如,在 Qt 中,您可以只向在另一个线程上运行的对象发送信号。)
标签: c++ multithreading opencv