Thursday 12 April 2012

OpenCV waitKey() function

Basically waitKey is the function which suspends or pauses the process for a given time, say waitKey(10) will wait 10 millisecond until running the following codes, while waitKey(0) will run the following codes unless any key is pressed.

The other important role of this function is to fetch and handle events in HighGUI calling. For example, in a loop, if you create a window (using namedWindow) and the display on the screen using imshow(). In this scenario, nothing is shown on the screen until waitKey is called, since HighGUI does not give any time for imshow to process the drawing events.


/* Assuming this is a while loop -> e.g. video stream where img is obtained from say web camera.*/    
cvShowImage("Window",img);
/* A small interval of 10 milliseconds. This may be necessary to display the image correctly */
cvWaitKey(10);  
/* to wait until user feeds keyboard input replace with cvWaitKey(0); */

No comments:

Post a Comment