Ask Your Question
0

Handling non-key or mouse events

asked 2017-10-05 14:56:56 -0600

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()?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-10-05 23:36:25 -0600

berak gravatar image

updated 2017-10-05 23:43:06 -0600

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 .

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-10-05 14:56:56 -0600

Seen: 668 times

Last updated: Oct 05 '17