我用OpenCV捕獲攝像頭圖像。這工作正常。但是,如果我想在按下按鈕時關閉OpenCV,它不起作用(同時嘗試使用cvDestroyWindow("NameOfWindow")
和cvDestroyAllWindows()
)。窗口保持打開狀態,應用程序仍在運行。試圖關閉OpenCV窗口沒有效果
OpenCV是在與主GUI分開的線程上初始化的。
我在我的Mac上使用Juce框架和C++。但同樣的問題也發生在使用Qt和Windows窗體的Windows上,當OpenCV窗口有它自己的cvNamedWindow時。
這裏是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) {
}
是否'cvDestroyAllWindows();'當它通過一個簡單的按鈕按下觸發? –
你是否在產生窗口的同一個線程中調用'cvDestroy'(即叫做'cvNamedWindow')? – Jacob
@Dan Cecile是的,我試過這個,但它不起作用。 – sn3ek