Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does waitKey (30) mean in OpenCV? [duplicate]

Tags:

c++

opencv

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!

like image 221
Imbarfar Avatar asked Sep 17 '12 01:09

Imbarfar


People also ask

What does waitKey do in OpenCV?

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.

What does waitKey return?

waitkey(1) waits for 1 ms and returns the code of the key on keyboard if it is pressed.

What is cv2 waitKey 1 & 0xFF?

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.

Is cv2 waitKey necessary?

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.


1 Answers

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 :)

like image 192
tito Avatar answered Sep 21 '22 21:09

tito