Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Block until window closed

I would like to display a window, and block the program execution until the user decides to continue. This is done normally the following way:

Mat img1,img2;
//...process...
namedWindow("Image1",WINDOW_NORMAL);
imshow("Image1",img1);
waitKey();
destroyAllWindows();
namedWindow("Image2",WINDOW_NORMAL);
imshow("Image2",img2);

The only problem with this approach is if the user instinctively closes the window using the X button. Then, as no HighGUI windows are active, waitKey() will never return and the program blocks.

Is there any solution, so the program waits a keypress OR the window to be closed?