Can't get waitKey() to work

My head is getting sore. What am I doing wrong?

This:

import cv2

print(“here”)
cv2.waitKey(5000000)
print(“jp”)
cv2.destroyAllWindows()

does not wait whether I have 5,000,000, 0 (zero), or 1 as argument.

Just prints:

here
jp


(program exited with code: 0)
Press return to continue

Also, how do I insert code tags. Debian 12, python, xfce desktop, using Geany.

Thanks,

JP

It’s for GUI event processing, not for waiting.

if there are no imshow() windows, then waitKey() returns immediately.

do not open an imshow() window merely to make waitKey() wait. only open an imshow() window if you actually intend to show an image.

if you want a delay in a non-GUI program, use time.sleep(...).

if you actually have GUI, then you must not use time.sleep() in the thread that handles the GUI (typically the main thread).

It’s for GUI event processing, not for waiting.

if there are no imshow() windows, then waitKey() returns immediately.

Ah, that explains a lot.

if you want a delay in a non-GUI program, use time.sleep(...).

Was monkeying around with time lib (it worked) and the keyboard lib, but could not get that to work mainly because of permissions issues (Debian O/S).

So on this project I have decided to go to an RPi since RPi has the GPIO built in (which should simplify the hand shaking, ie: just use a button) and an RPi was the planned end goal anyways (I just thought that it would be easier to do some of the programming experimentation in my armchair on a laptop).

Thank you for responding CRackwitz,

JP.

it’s a weird library. it might interface with the terminal that your program runs in, but it might also interface with some GUI/HID facility that lets it set global hotkeys/hooks.

things like kbhit() and getch() have almost died out, and people over 30 even know of them.