Open In App

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. 



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)

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)

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)

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.




# 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:

 

Article Tags :