OpenCV DestroyWindow does not work on Ubuntu. How to close the window?

In the following code, DestroyWindow or DestroyAllWindows cannot close the window opened by ShowImage. When I tried to close it by clicking the close button, the window was paused. After killing the window, all IDLE closed.

import cv image = cv.LoadImage("../lena.bmp", 0) cv.NamedWindow("test") cv.ShowImage("test", image) cv.WaitKey() cv.DestroyWindow("test") #or cv.DestroyAllWindows() 

I am using OpenCV 2.4.2 with Python 2.7 on Ubuntu 12.04 LTS.

I did something wrong and how can I close the create by ShowImage window?

+7
source share
2 answers

I believe that cv.WaitKey should be called with a number as an argument, either 0 or n> 0, where n> 0 specifies the number of milliseconds to wait.

cv.WaitKey (0) will wait indefinitely for a key press, and then returns an input character. Pressing the keyboard button should close the window if you have not tried it yet.

+2
source

Try the following:

 c = cv.WaitKey(27) if c == 27: cv.DestroyAllWindows("Test") break 
+1
source

All Articles