Python OpenCV - startWindowThread() Function
Last Updated :
03 Jan, 2023
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.
Syntax: cv2.startWindowThread()
Parameters: None
Return Value: It doesn’t returns anything.
Stepwise Implementation:
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.
import cv2
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.
cv2.startWindowThread()
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.
cv2.namedWindow(window_name,prop_value)
- 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.
cv2.imshow(window_name, image)
- 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.
cv2.waitKey(0)
Example:
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.
Python3
# Python program for OpenCV
# startWindowThread() function
# Import the library OpenCV
import cv2
# Read the image
img = cv2.imread("gfg_black.png")
# Use high GUI windows
cv2.startWindowThread()
# Name the GUI app
cv2.namedWindow("preview", cv2.WINDOW_NORMAL)
# Display the image on GUI app
cv2.imshow("preview", img)
# Make Python sleep for unlimited time
cv2.waitKey(0)
Output:
Similar Reads
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 - 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 - 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. Example: Pythonim
2 min read
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
How to Install OpenCV for Python on Windows? Prerequisite: Python Language Introduction  OpenCV is the huge open-source library for computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in todayâs systems. By using it, one can process images and videos to identify
4 min read
Python OpenCV â cv2.transpose() method OpenCV is a library of programming functions mainly aimed at real-time computer vision. cv2.transpose() method is used to transpose a 2D array. The function cv::transpose rotate the image 90 degrees Counter clockwise. Syntax: cv2.cv.transpose( src[, dst] ) Parameters: src: It is the image whose matr
1 min read
Python - Move() function in wxPython In this particular article we will learn, how can we move our window to a particular point. This can be achieved using Move() function in wx.Window class of wxPython. Move() takes x and y points to move window to a particularx, y point. Syntax : wx.Move(self, x, y, flags=SIZE_USE_EXISTING) Parameter
1 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
Python OpenCV - setTrackbarMin() In this article, we will discuss how to set the minimum position of the trackbar. The minimum value of the track bar can be achieved using the function setTrackbarMin() from the OpenCV package in python. This function sets the minimum position of the specified trackbar in the specified window after
4 min read