Ask Your Question
0

Handling non-key or mouse events

asked Oct 5 '17

mp0317 gravatar image

I am using a touchscreen to display images with imshow() to show a random picture from an external folder. I want to be able to exit imshow() when the screen is touched, rather than when a key is pressed. Is it possible to set up a custom event to kill imshow()?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
0

answered Oct 6 '17

berak gravatar image

updated Oct 6 '17

you do not have to "kill imshow()". all you have to do is "catch" the event you're looking for, and make it break the loop.

a typical program looks like this:

while True:
     img = cv2.imread("some_random.png")
     # some processing

     if my_event_happened:  # insert your event here!
            break

     cv2 imshow("I", img)
     cv2.waitKey(20)

note, that you still need the waitKey() call for showing the image !

also, take a look at the py gui tutorials .

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Oct 5 '17

Seen: 712 times

Last updated: Oct 05 '17