Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python OpenCV – moveWindow() Function

  • Last Updated : 28 Jan, 2022

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 specific position moveWindow() function of OpenCV will do it. 

Syntax: cv2.moveWindow(window_Name,x,y)

Parameters:

  • window_name: name of the window which you want to move at particular position
  • x: Value of x coordinate
  • y: Value of y coordinate

Return: None

Example 1: Image with a specific position

In this example, we will display only one window at a particular position.

Used image:

Code:

Python3




# Import OpenCV library
import cv2
 
# Read an Image
img = cv2.imread("Documents/geekslogo.png",
                 cv2.IMREAD_COLOR)
 
# Display image using imshow() function
cv2.imshow("I2", img)
 
# Move window to (10,50) position
# using moveWindow() function
cv2.moveWindow("I2", 10, 50)
 
# Wait for user to press any key
cv2.waitKey(0)
 
# Close all opened windows
cv2.destroyAllWindows()

Output:

Example 2: Multiple images in different positions

In this example, we will display Multiple windows at a particular position.

Used image:

Python3




# Import OpenCV library
import cv2
 
# Read four Images
img1 = cv2.imread("Documents/geekslogo.png", cv2.IMREAD_COLOR)
img2 = cv2.imread("Documents/geekslogo2.png", cv2.IMREAD_COLOR)
img3 = cv2.imread("Documents/geekslogo3.png", cv2.IMREAD_COLOR)
img4 = cv2.imread("Documents/geekslogo4.png", cv2.IMREAD_COLOR)
 
 
# Display images using imshow() function
cv2.imshow("I1", img1)
cv2.imshow("I2", img2)
cv2.imshow("I3", img3)
cv2.imshow("I4", img4)
 
# Move window to (10,50) position
# using moveWindow() function
cv2.moveWindow("I1", 10, 50)
cv2.moveWindow("I2", 650, 50)
cv2.moveWindow("I3", 10, 500)
cv2.moveWindow("I4", 650, 500)
 
# Wait for user to press any key
cv2.waitKey(0)
 
# Close all opened windows
cv2.destroyAllWindows()

Output:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!