OpenCV:自动调整窗口大小以显示图像
问题描述:
当显示图像以适合图像的宽度和高度时,是否有一种方法可以强制OpenCV(cv2.imshow()
)显示的窗口,而无需通过鼠标来调整其大小?
Is there a way to force the window displayed by OpenCV (cv2.imshow()
)when displaying an image to fit to the width and height of the image without the need to resize by the mouse it for that ?
答
您需要传递 CV_WINDOW_AUTOSIZE 在创建namedWindow时(如果导入cv2
而不是cv
,则为WINDOW_AUTOSIZE
)
You need to pass CV_WINDOW_AUTOSIZE when creating the namedWindow (or WINDOW_AUTOSIZE
if you import cv2
instead of cv
)
这里是一个例子:
cv2.namedWindow("window", cv2.WINDOW_AUTOSIZE)
# or cv.namedWindow("window",cv.CV_WINDOW_AUTOSIZE)
cv2.imshow("window", yourimage)