OpenCV 有没有办法自动调整显示图像到屏幕的大小?
OpenCV is there a way to resize the showed image to the screen automatically?
我正在使用 opencv 来显示图像。问题是图像很大,所以它比我巨大的显示器还大。
有没有办法显示此图像 自动 调整大小以适合我的屏幕?
请注意,此处类似问题的许多答案可分为两类:
- 他们建议在 namedWindow 函数中使用一个选项,但这 没有 解决问题(我试过并仔细阅读了文档,它从未声称它确实解决了这个问题)
- 使用调整大小手动调整图像大小。不是自动的。但是我怎么知道要调整大小的值呢?
编辑:有人要求我报告我的说法,即 WINDOW_NORMAL 没有解决问题。我面前有一个脚本,我首先要做的是
cv.imshow("window",image)
cv.waitKey()
然后使用相同的脚本
cv.namedWindow("window", cv.WINDOW_NORMAL)
#image = cv.resize(image, (960, 540))
#image = cv.resize(image, (1280, 800))
cv.imshow("window",image)
cv.waitKey()
结果是一样的。 window 一如既往的巨大。
现在让我们看看 docs
Parameters:
name – Name of the window in the window caption that may be used as a window identifier.
flags –
Flags of the window. The supported flags are:
WINDOW_NORMAL If this is set, the user can resize the window (no constraint).
WINDOW_AUTOSIZE If this is set, the window size is automatically adjusted to fit the displayed image (see imshow() ), and you cannot change the window size manually.
WINDOW_OPENGL If this is set, the window will be created with OpenGL support.
如您所见,它清楚地表明 用户可以调整 window(无约束) 的大小,并且没有任何部分表明 AUTOMATICALLY
所以没有解决这个问题的问题
您可以尝试使用以下库来获取显示器的 X 和 Y 值:
import pyautogui #pip install pyautogui
x = pyautogui.size()[0] # getting the width of the screen
y = pyautogui.size()[1] # getting the length of the screen
print(x,y)
类似于 Dimitar Veljanovski 发布的内容(谢谢!)我是这样做的。它不是自动的,也不会占据整个屏幕,但我还没有收到对此的答复
h, w, c = image.shape
cv.namedWindow("window",cv.WINDOW_NORMAL)
image=cv.resize(image, (w//3,h//3))
cv.imshow("window",image)
我正在使用 opencv 来显示图像。问题是图像很大,所以它比我巨大的显示器还大。 有没有办法显示此图像 自动 调整大小以适合我的屏幕?
请注意,此处类似问题的许多答案可分为两类:
- 他们建议在 namedWindow 函数中使用一个选项,但这 没有 解决问题(我试过并仔细阅读了文档,它从未声称它确实解决了这个问题)
- 使用调整大小手动调整图像大小。不是自动的。但是我怎么知道要调整大小的值呢?
编辑:有人要求我报告我的说法,即 WINDOW_NORMAL 没有解决问题。我面前有一个脚本,我首先要做的是
cv.imshow("window",image)
cv.waitKey()
然后使用相同的脚本
cv.namedWindow("window", cv.WINDOW_NORMAL)
#image = cv.resize(image, (960, 540))
#image = cv.resize(image, (1280, 800))
cv.imshow("window",image)
cv.waitKey()
结果是一样的。 window 一如既往的巨大。 现在让我们看看 docs
Parameters:
name – Name of the window in the window caption that may be used as a window identifier. flags – Flags of the window. The supported flags are: WINDOW_NORMAL If this is set, the user can resize the window (no constraint). WINDOW_AUTOSIZE If this is set, the window size is automatically adjusted to fit the displayed image (see imshow() ), and you cannot change the window size manually. WINDOW_OPENGL If this is set, the window will be created with OpenGL support.
如您所见,它清楚地表明 用户可以调整 window(无约束) 的大小,并且没有任何部分表明 AUTOMATICALLY 所以没有解决这个问题的问题
您可以尝试使用以下库来获取显示器的 X 和 Y 值:
import pyautogui #pip install pyautogui
x = pyautogui.size()[0] # getting the width of the screen
y = pyautogui.size()[1] # getting the length of the screen
print(x,y)
类似于 Dimitar Veljanovski 发布的内容(谢谢!)我是这样做的。它不是自动的,也不会占据整个屏幕,但我还没有收到对此的答复
h, w, c = image.shape
cv.namedWindow("window",cv.WINDOW_NORMAL)
image=cv.resize(image, (w//3,h//3))
cv.imshow("window",image)