Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does OpenCV's cvWaitKey( ) function do?

Tags:

c++

c

opencv

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.

like image 270
Simplicity Avatar asked Mar 07 '11 08:03

Simplicity


People also ask

What does CV waitKey do?

Python OpenCV – waitKey() Function 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 cv2 waitKey return?

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

Is cv2 waitKey necessary?

4. cv2. waitKey() This function is very important, without this function cv2.

What does cv2 waitKey 1 & 0xFF do?

Answer #1: 0xFF is a hexadecimal constant which is 11111111 in binary. By using bitwise AND ( & ) with this constant, it leaves only the last 8 bits of the original (in this case, whatever cv2. waitKey(0) is). Answered By: Kevin W.


1 Answers

cvWaitKey(x) / cv::waitKey(x) does two things:

  1. 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 is zero, it waits indefinitely for the key press.)
  2. 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().

like image 84
SuperElectric Avatar answered Oct 23 '22 11:10

SuperElectric