Resize OpenCV Window Smallest Size Python
In the OpenCV library in Python, you can use the cv2.namedWindow() function to set window properties, including the window size. Specifically, you can set the window property to cv2.WINDOW_NORMAL, and then use the cv2.resizeWindow() function to set the window size. Here is an example code:
import cv2
# 创建一个名为"image"的窗口,并设置属性为WINDOW_NORMAL
cv2.namedWindow("image", cv2.WINDOW_NORMAL)
# 将窗口大小设置为最小值(1x1)
cv2.resizeWindow("image", 1, 1)
# 加载图像
image = cv2.imread("image.jpg")
# 在窗口中显示图像
cv2.imshow("image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
In the example provided above, a window named “image” is first created using the cv2.namedWindow() function with the attribute set to cv2.WINDOW_NORMAL. The window size is then set to the minimum value (1×1) using the cv2.resizeWindow() function. Finally, the image is displayed in the window using the cv2.imshow() function.