OpenCV版本2.2,C++接口。帶鼠標問題的OpenCV關閉窗口
當顯示在用下面的代碼的窗口的加載的圖像片斷
cvStartWindowThread();
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow("Display window", CV_WINDOW_AUTOSIZE);// Create a window for display.
imshow("Display window", image);
while(1) {
if(cvWaitKey(100) == 27) break;
}
通過用鼠標按close button
,而不是使用退出鍵關閉圖像時我面臨的一個問題。
在這種情況下,我的程序將被阻止在while
中,退出它的唯一方法是停止執行,這顯然是不希望的。
是否有任何控制close button
被按下的功能? 以這種方式,我可以將它添加到while循環中,如下所示:
E.g.
while(1) {
if(cvWaitKey(100) == 27) break;
if(cvCloseButtonPressed == 1) break; <--- purely invented method I'm looking for...
}
請注意,這隻適用於Windows。 – 2012-03-27 10:29:17
@MichalKottman實際上它也在使用g ++編譯器的linux上工作,只是有一點不同的sintax。這是我正在尋找的功能,謝謝! – Matteo 2012-03-27 15:27:59
注意:由於在MinGW上執行opencv的bug,它似乎不適用於Windows + MinGW編譯器。我不知道什麼時候它會被修復,或者它已經被修復了(因爲我沒有定期更新到最新版本)。 – 2016-01-06 09:25:11