What happens during the execution of cvWaitKey()
? What are some typical use cases? I saw it in OpenCV reference but the documentation isn't clear on its exact purpose.
相关问题
- Sorting 3 numbers without branching [closed]
- Multiple sockets for clients to connect to
- How to get the background from multiple images by
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
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 ormillisecond
time provided.Note for anybody who may have had problems with the
cvWaitKey( )
function. If you are finding thatcvWaitKey(x)
is not waiting at all, make sure you actually have a window open (i.e.cvNamedWindow(...)
). Put thecvNamedWindow(...)
declaration BEFORE anycvWaitKey()
function calls.The
cvWaitKey
simply provides something of a delay. For example: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 after33ms
, a new frame would be shown. Hence, the was a dely or time interval of33ms
between each frame being shown on the screen. Hope this helps.waits milliseconds to check if the key is pressed, if pressed in that interval return its ascii value, otherwise it still -1
cvWaitKey(x) / cv::waitKey(x)
does two things: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 is zero, it waits indefinitely for the key press.)cv::namedWindow()
, or showing images withcv::imshow()
.A common mistake for opencv newcomers is to call
cv::imshow()
in a loop through video frames, without following up each draw withcv::waitKey(30)
. In this case, nothing appears on screen, because highgui is never given time to process the draw requests fromcv::imshow()
.