Possible Duplicate:
OpenCV - cvWaitKey( )
I want to filter the video frame.
for(;;) { cap.read( frame); medianBlur(frame,framedst,5); imshow("frame",frame); imshow("framedst",framedst); if( waitKey (30) >= 0) break; }
What does the waitKey(30)
mean? Because if I comment out the line if( waitKey (30) >= 0) break;
, the above code doesn't work!
waitkey() function of Python OpenCV allows users to display a window for given milliseconds or until any key is pressed. It takes time in milliseconds as a parameter and waits for the given time to destroy the window, if 0 is passed in the argument it waits till any key is pressed.
waitkey(1) waits for 1 ms and returns the code of the key on keyboard if it is pressed.
In this code, if cv2.waitKey(0) & 0xFF == ord('q'): break. The waitKey(0) function returns -1 when no input is made whatsoever. As soon the event occurs i.e. a Button is pressed it returns a 32-bit integer.
waitKey() , the NOTE section mentions that 'This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing. ' You can notice that without the cv2.
The function waitKey()
waits for a key event for a "delay" (here, 30 milliseconds). As explained in the OpenCV documentation, HighGui (imshow()
is a function of HighGui) need a call of waitKey regularly, in order to process its event loop.
Ie, if you don't call waitKey, HighGui cannot process windows events like redraw, resizing, input event, etc. So just call it, even with a 1ms delay :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With