Ask Your Question
0

Python3 can I replace waitKey() with an input using curses?

asked 2020-06-22 15:56:57 -0600

NikosOpenCV gravatar image

updated 2020-06-23 12:11:41 -0600

supra56 gravatar image

Python3... 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(curses do NOT wait/stop the other parts of program until user give an input ) So, 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()

input.nodelay(1) # set getch() non-blocking

I don't want to wait for a key,because the other parts of program sticks.

Thanks!!

edit retag flag offensive close merge delete

Comments

do you understand the difference between a console based an a gui based program ?

berak gravatar imageberak ( 2020-06-22 16:37:56 -0600 )edit

I asked if I can replace waitkey() function with an input that don't need to wait.

NikosOpenCV gravatar imageNikosOpenCV ( 2020-06-23 01:47:41 -0600 )edit

One mode comment: waitKey works in the window's event loop, while curses only works in the terminal (command line).

So if the image window has focus, you have to use waitKey, but if the terminal has focus, you need getch to read a keystroke.

kbarni gravatar imagekbarni ( 2020-06-25 04:35:49 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-06-23 01:59:14 -0600

berak gravatar image

updated 2020-06-23 02:45:14 -0600

no, as long as you use imshow(), you cannot replace or avoid it.

waitKey() contains the whole image drawing functionality / event loop, imshow() only copies an image pointer, so it's not only about processing keyboard input

edit flag offensive delete link more

Comments

Can I delete the if statement in the following code?? When I delete it and then run the program ,it shows a white video screen:

import cv2

cap = cv2.VideoCapture(0);              
while(cap.isOpened()):                   
    ret , frame = cap.read()              

    cv2.imshow('I see you !!!' , frame)   
    if cv2.waitKey(1) == ord('q'):       
        break
cap.release()                           
cv2.destroyAllWindows()
NikosOpenCV gravatar imageNikosOpenCV ( 2020-06-23 07:10:42 -0600 )edit

When I delete it and then run the program ,it shows a white video screen.

yea, nothing will get updated, ever (the white color is arbitrary)

Can I delete the if statement in the following code?

again, no.

berak gravatar imageberak ( 2020-06-23 07:41:18 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-06-22 15:56:57 -0600

Seen: 2,203 times

Last updated: Jun 23 '20