I have the following code:
total_frames = 50
cv2.cv.NamedWindow("Dragonfly Simulation")
cv2.cv.StartWindowThread()
for i in range(total_frames):
# do stuff
img_name = # something
img = cv2.cv.LoadImage(img_name)
cv2.cv.ShowImage("Dragonfly Simulation", img)
cv2.cv.WaitKey(2)
cv2.cv.DestroyWindow("Dragonfly Simulation")
cv2.cv.WaitKey(1)
# rest of code
So what does it do:
- Opens a window
- In a loop, shows an image on the window
- Once finished, closes the window
- Runs the rest of the code
However in this case I have the total_frame
given before. I don't want that.
Instead, I want a code that does the following:
- Opens a window
- In a loop, shows an image on the window
- Waits for the user to close that window
- When the user closes that window, exit loop, goes on with the rest of the code.
However, I cannot find a function in OpenCV that can detect when user closes a window. Can anyone suggest a workaround please?