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 simplified interface for displaying images and videos from OpenCV code.
Return Value: It doesn’t returns anything.
Step 1: First of all, import the OpenCV library.:
Here, we are importing the cv2 library, the cv2 is the OpenCV package that helps us to call the imread(), startWindowThread(), namedWindow(), and imshow() functions respectively.
Step 2: Now, read the image using imread() function:
In this step, we have used the imread() function that loads an image from the specified file.
img = cv2.imread(path, flag)
- path: Path of the image to be read.
- flag: Way in which image should be read. The default value of the flag is cv2.IMREAD_COLOR.
Step 3: Then, call the startWindowThread() function for using the high GUI windows:
In this step, we have used a startWindowThread() function which displays the simplified interface for displaying images and videos from OpenCV code.
Step 4: Next, assign the name and size to your GUI app:
In this step, we have used a namedWindow() function which is used to create a window with a suitable name and size to display images and videos on the screen.
- window_name: Name of the window.
- prop_value: New value of the window property such as cv2.WND_PROP_FULLSCREEN, cv2.WND_PROP_AUTOSIZE, cv2.WND_PROP_ASPECT_RATIO, etc.
Step 5: Further, display the image on the GUI app:
In this step, we have used the imshow() function that is used to display an image in a window. The window automatically fits the image size.
- window_name: A string representing the name of the window in which the image is to be displayed.
- image: It is the image that is to be displayed.
Step 6: Finally, make python sleep for an unlimited time:
In this step, we have used a waitKey() function that allows users to display a window for a specified time or until any key is pressed.
In this example, we have used the image ‘gfg_black.png’ (link). We have also used the startWindowThread() function as a simplified interface for displaying images and videos from OpenCV code.