2011-08-21 3 views
4

OpenCV로 웹캠 이미지를 캡처하고 있습니다. 그건 잘 작동합니다. 그러나 버튼을 눌렀을 때 OpenCV를 닫으려는 경우 작동하지 않습니다 (cvDestroyWindow("NameOfWindow")cvDestroyAllWindows() 모두 시도). 창은 계속 열려 있고 응용 프로그램은 계속 실행 중입니다.OpenCV 창을 닫으려고해도 아무런 효과가 없습니다.

OpenCV는 기본 GUI의 별도 스레드에서 초기화되었습니다.

Mac에서 C++과 함께 Juce Framework를 사용하고 있습니다. OpenCV Window에 자체 cvNamedWindow가있는 경우 Qt 및 Windows Forms이있는 Windows에서도 동일한 문제가 발생합니다. 당신이 누락 될 수 있습니다 조각이 cvStartWindowThread 함수를 호출이다

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) { 
} 
+0

합니까'cvDestroyAllWindows() :

는 GCC로 컴파일 예제를 실행하려면? –

+1

윈도우를 생성 한 동일한 스레드 (즉,'cvNamedWindow ')에서'cvDestroy'를 호출합니까? – Jacob

+0

@Dan Cecile 예이 시도했지만 작동하지 않습니다. – sn3ek

답변

5

:

다음은 VST 플러그인 에디터 클래스의 기본 코드입니다.

Linux에서 GTK HighGUI를 사용하여 cvStartWindowThread을 호출 할 때까지이 예가 문제를 재현했습니다. 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; 
} 

, 당신의 cvDestroy 호출 후에 cvWaitKey에 추가 호출을 수행하려고합니다. ;`가 간단한 버튼 누름에 의해 실행되는 경우

g++ destroy_window.cpp -o destroy_window -lopencv_core -lopencv_highgui 
+0

Xcode4에서 콘솔 응용 프로그램으로 코드를 시도했지만 정상적으로 작동합니다. 하지만 내 Juce VST 플러그인에서 동일한 코드를 실행하려고하면 윈도우가 파괴 방법을 인식하는 것 같지만 opencv 창이 멈추고 아무 일도 일어나지 않습니다. destroy 메소드 다음에 몇 가지 로그 메시지를 던졌지 만 로그 파일에 나타나지 않으므로 '// 창이 닫혔는지 확인한 후'확인 코드가 실행되지 않습니다. – sn3ek

+0

@ sn3ek 나는 멀티 스레딩 데드락처럼 들린다. 'cvDestroyWindow'가 실행되기 시작했지만, 계속하기 전에 다른 스레드를 대기합니다. 'cvDestroyWindow'가 호출되기 전에 디버거를 사용하여 프로그램을 일시 중지하고 다른 스레드가 실행 중인지 확인할 수 있습니까? –

+0

의견을 수정해야합니다. 코드'cvDestroyWindow()'가 실행됩니다. 나는 몇 가지 로그 메시지로 시도했다. 그러나 창은 사라지지 않을 것이지만, 나머지 플러그인은 잘 닫혔다. 그리고 나는 새로운 opencv 창으로 잘 작동하는 플러그인을 다시 열 수있다. 이상한데! – sn3ek

관련 문제