1

I need the user input after showing an image, but the problem is that the image window will not close and will freeze. Do you have some solution or alternative that I can use to get the user input?

Code:

import cv2

img = cv2.imread("begin.jpg")
cv2.imshow("test",img)
cv2.destroyAllWindows()
raw_input("test:")

Problem: Window that show image will not close

Cause: raw_input(). Removing the raw_input() the window closes as expected.

I expect more than one character from the user.

Thank you so much

dvsaraiva
  • 491
  • 1
  • 6
  • 13
  • 1
    If your code ran as expected it would actually show and hide the window immediately. Anyway, `waitKey` is the likely the function you want to use here. It forces a refresh of the window either immediately, after a timeout, or after a key press. – 101 Jun 06 '15 at 22:11
  • Yes, if the code ran as expected the window would show and hide immediately. What I do not understand is why the raw_input makes the destroyAllWindows does not work... About waitKey, my problem is not that the window will show and hide immediately, I put the code like this to show that the raw_input, does not let the window to close. With waitKey one can also read a char, but I would like to receive more than one... – dvsaraiva Jun 07 '15 at 18:33
  • Don't use `waitKey` as the user input, except for them to close the window. Then collect their input with `raw_input`. – 101 Jun 07 '15 at 20:15
  • Yes, that is what I want...but the problem is that the window does not close. – dvsaraiva Jun 08 '15 at 20:25
  • Put another `waitKey` after the destroy window command? – 101 Jun 08 '15 at 21:39
  • That was the solution that I did before posting, but thank you for the idea ;) I am intrigued with this behavior of destroy_window and raw_input...I also tried to run in a separate thread the code for opening and close the window, but even after the end of the thread, the window does not close if there is a raw_input following the end of the thread... – dvsaraiva Jun 08 '15 at 23:16
  • 1
    http://stackoverflow.com/questions/6116564/destroywindow-does-not-close-window-on-mac-using-python-and-opencv – electron1979 Jul 28 '15 at 13:24

1 Answers1

1

I had the same problem: I found the next info in openCV DevZone, it looks like a bug: http://code.opencv.org/issues/2911 it works for me.

Arnok
  • 11
  • 1