Python OpenCV waitKey() Function (original) (raw)
Last Updated : 03 Jan, 2023
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.
Examples 1: Display image with a time limit
Using waitKey() method we show the image for 5 seconds before it automatically closes. The code will be as follows:
Python `
importing cv2 module
import cv2
read the image
img = cv2.imread("gfg_logo.png")
showing the image
cv2.imshow('gfg', img)
waiting using waitKey method
cv2.waitKey(5000)
`
Output:
Example 2: Display image until key pressed
Now we can see one example of passing 0 as the parameter. This time instead of automatically closing the window would wait till any key is pressed. The code will be:
Python `
importing cv2 module
import cv2
read the image
img = cv2.imread("gfg_logo.png")
showing the image
cv2.imshow('gfg', img)
waiting using waitKey method
cv2.waitKey(0)
`
Output:
Similar Reads
- Python OpenCV - waitKeyEx() Function Python OpenCv waitKeyEx() method is similar to waitKey() method but it also returns the full key code. The key code which is returned is implementation-specific and depends on the used backend: QT/GTK/Win32/etc. Syntax: cv2.waitKey(delay) Parameters: delay: The time in milliseconds after which windo 2 min read
- Python OpenCV - setWindowTitle() Function Python OpenCV setWindowTitle() method used for giving the title of the windows. It takes 2 parameters that are windows name and the title that needs to be given. Both the parameters are expected to be of string type. Syntax: cv2.setWindowTitle( winname, title )Â Parameters: winname: windows nametitl 1 min read
- Python OpenCV - startWindowThread() Function This article will discuss how to use the python OpenCV startWindowThread() function. Do you want to display images and videos using a simplified interface through an OpenCV code? Then, you must check out the OpenCV startWindowsThread() function, which lets you use the high GUI windows, i.e., a simpl 3 min read
- Python OpenCV - resizeWindow() Function resizeWindow() method in Python OpenCV is used to resize window displaying images/videos to a specific size. The specified window size is for images excluding toolbars. This only works for created windows having flags other than CV_WINDOW_AUTOSIZE. Syntax: cv2.resizeWindow(window_name, width, height 1 min read
- Python OpenCV - selectroi() Function In this article, we are going to see an interesting application of the OpenCV library, which is selectROI(). With this method, we can select a range of interest in an image manually by selecting the area on the image. Syntax:Â cv2.selectROI(Window_name, source image) Parameter: window_name: Â name of 3 min read
- Python OpenCV - Canny() Function Canny edge detection algorithm is used in computer vision for identifying edges within an image. It helps in highlighting boundaries which are important for tasks like object detection and image segmentation. In this article, we will see how OpenCV's built-in Canny() function detects edges in an ima 3 min read
- Python OpenCV - imencode() Function Python OpenCV imencode() function converts (encodes) image formats into streaming data and stores it in-memory cache. It is mostly used to compress image data formats in order to make network transfer easier. Basic example of imencode() FunctionExample 1: We began by importing the necessary librarie 2 min read
- Python OpenCV - moveWindow() Function When we show the image using the imshow() function output window will open at the center or default position of a computer screen. Even if there are multiple image windows all windows will be displayed at the same position and we have to move windows manually. If we want to show image windows at a s 2 min read
- Python OpenCV - namedWindow() Function Python OpenCV namedWindow() method is used to create a window with a suitable name and size to display images and videos on the screen. The image by default is displayed in its original size, so we may need to resize the image for it to fit our screen. Created windows are referred by their names and 3 min read
- turtle.onkey() function in Python The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support. turtle.onkey() This function is used to bind fun to the key-release event of the ke 1 min read