NickAsk
Posts: 61
Joined: Mon Mar 23, 2020 7:10 pm

Other part of program sticks with camera using opencv

Mon Jun 22, 2020 8:23 pm

Hello.I have a program and a part of it is to open a camera with opencv
Another part of program is to give inputs using curses(do NOT wait/stop the other parts of program until user give an input )
But when I open a camera AND then give an input the program sticks a little bit and this is very very bad.
I think the problem is to --> cv2.waitkey(1) (Part of camera) ,because(maybe) waits for user input (I don't know)-> if(cv2.waitkey(1) == ord('q'):

Can I replace cv2.waitkey(1) with the following:???
input = curses.initscr()
curses.noecho()
give_move.nodelay(1) # set getch() non-blocking

Thanks!!

Heater
Posts: 15949
Joined: Tue Jul 17, 2012 3:02 pm

Re: Other part of program sticks with camera using opencv

Mon Jun 22, 2020 10:39 pm

Why do you insist on starting two threads for the same question? That is not appreciated here.
I think the problem is to --> cv2.waitkey(1) (Part of camera) ,because(maybe) ,because(maybe) waits for user input (I don't know)...
You know, if you type "opencv waitkey" into google search you immediately find yourself in the opencv documentation. And then you know what "waitkey" does. It's quicker than asking here!

https://docs.opencv.org/2.4/modules/hig ... ht=waitkey
Memory in C++ is a leaky abstraction .

NickAsk
Posts: 61
Joined: Mon Mar 23, 2020 7:10 pm

Re: Other part of program sticks with camera using opencv

Tue Jun 23, 2020 6:54 am

Ok I'm sorry
The waitkey function waits a few ms for user input but I want to have an input that don't need to wait not at all.
So my question is how can I replace waitkey with another input that don't need to wait.

Thanks.

Heater
Posts: 15949
Joined: Tue Jul 17, 2012 3:02 pm

Re: Other part of program sticks with camera using opencv

Tue Jun 23, 2020 7:15 am

Perhaps with the pynput module https://pypi.org/project/pynput/:

Code: Select all

from pynput import keyboard

def on_press(key):
    try:
        print('alphanumeric key {0} pressed'.format(
            key.char))
    except AttributeError:
        print('special key {0} pressed'.format(
            key))

def on_release(key):
    print('{0} released'.format(
        key))
    if key == keyboard.Key.esc:
        # Stop listener
        return False

# Collect events until released
with keyboard.Listener(
        on_press=on_press,
        on_release=on_release) as listener:
    listener.join()

# ...or, in a non-blocking fashion:
listener = keyboard.Listener(
    on_press=on_press,
    on_release=on_release)
listener.start()
Memory in C++ is a leaky abstraction .

Return to “General discussion”