Python OpenCV – resizeWindow()函数
Python OpenCV 中的 resizeWindow() 方法用于将显示图像/视频的窗口调整为特定大小。指定的窗口大小适用于不包括工具栏的图像。这仅适用于创建的具有除CV_WINDOW_AUTOSIZE 以外的标志的窗口。
Syntax: cv2.resizeWindow(window_name, width, height)
Parameters:
- window_name: Name of the window that will display image/video
- width: New window width (integer type)
- height: New window height (integer type)
Return Value: It doesn’t return anything
用于以下示例的图像:
示例 1:
Python3
# Python program to explain cv2.resizeWindow() method
# Importing cv2
import cv2
# Path
path = 'C:/Users/art/OneDrive/Desktop/geeks.png'
# Reading an image in default mode
image = cv2.imread(path)
# Naming a window
cv2.namedWindow("Resized_Window", cv2.WINDOW_NORMAL)
# Using resizeWindow()
cv2.resizeWindow("Resized_Window", 300, 700)
# Displaying the image
cv2.imshow("Resized_Window", image)
cv2.waitKey(0)
Python3
# Python program to explain cv2.resizeWindow() method
# Importing cv2
import cv2
# Path
path = 'C:/Users/art/OneDrive/Desktop/geeks.png'
# Reading an image in grayscale mode
image = cv2.imread(path, 0)
# Naming a window
cv2.namedWindow("Resize", cv2.WINDOW_NORMAL)
# Using resizeWindow()
cv2.resizeWindow("Resize", 700, 200)
# Displaying the image
cv2.imshow("Resize", image)
cv2.waitKey(0)
输出:
示例 2:
蟒蛇3
# Python program to explain cv2.resizeWindow() method
# Importing cv2
import cv2
# Path
path = 'C:/Users/art/OneDrive/Desktop/geeks.png'
# Reading an image in grayscale mode
image = cv2.imread(path, 0)
# Naming a window
cv2.namedWindow("Resize", cv2.WINDOW_NORMAL)
# Using resizeWindow()
cv2.resizeWindow("Resize", 700, 200)
# Displaying the image
cv2.imshow("Resize", image)
cv2.waitKey(0)
输出: