cvWaitKey(0) stops your program until you press a button.
cvWaitKey(10) doesn't stop your program but wake up and alert to end your program when you press a button. Its used into loops because cvWaitkey doesn't stop loop.
/* 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); */
It waits for x milliseconds for a key press on a OpenCV window (i.e. created from cv::imshow()). Note that it does not listen on stdin for console input. If a key was pressed during that time, it returns the key's ASCII code. Otherwise, it returns -1. (If x <= 0, it waits indefinitely for the key press.)
It handles any windowing events, such as creating windows with cv::namedWindow(), or showing images with cv::imshow().
A common mistake for opencv newcomers is to call cv::imshow() in a loop through video frames, without following up each draw with cv::waitKey(30). In this case, nothing appears on screen, because highgui is never given time to process the draw requests from cv::imshow().
The cvWaitKey simply provides something of a delay. For example:
char c = cvWaitKey(33);
if( c == 27 ) break;
Tis was apart of my code in which a video was loaded into openCV and the frames outputted. The 33 number in the code means that after 33ms, a new frame would be shown. Hence, the was a dely or time interval of 33ms between each frame being shown on the screen.
Hope this helps.
cvWaitKey(milliseconds) simply wait for milliseconds provided as a parameter for a next key stroke of keyboard.
Human eyes not able to see the thing moving in less than 1/10 second, so we use this to hold same image frame for some time on screen. As soon as the key of keyboard is pressed the next operation will be perform.
In short cvWaitKey(milliseconds) wait either for key press or millisecond time provided.
Note for anybody who may have had problems with the cvWaitKey( ) function. If you are finding that cvWaitKey(x) is not waiting at all, make sure you actually have a window open (i.e. cvNamedWindow(...)). Put the cvNamedWindow(...) declaration BEFORE any cvWaitKey() function calls.