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 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 cv2
img = cv2.imread( "Documents/geekslogo.png" ,
cv2.IMREAD_COLOR)
cv2.imshow( "I2" , img)
cv2.moveWindow( "I2" , 10 , 50 )
cv2.waitKey( 0 )
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 cv2
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)
cv2.imshow( "I1" , img1)
cv2.imshow( "I2" , img2)
cv2.imshow( "I3" , img3)
cv2.imshow( "I4" , img4)
cv2.moveWindow( "I1" , 10 , 50 )
cv2.moveWindow( "I2" , 650 , 50 )
cv2.moveWindow( "I3" , 10 , 500 )
cv2.moveWindow( "I4" , 650 , 500 )
cv2.waitKey( 0 )
cv2.destroyAllWindows()
|
Output:
Last Updated :
03 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...