如何在opencv2 python中调整窗口大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/16815194/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resize window in opencv2 python
提问by Bak
I am using opencv 2 with a webcam. I can get the video stream and process it, but I can't seem to figure out a way to resize the display window. I have some video images stacked horizontally, but the image dimension is very small that it's difficult to see things.
我正在使用带有网络摄像头的 opencv 2。我可以获取视频流并对其进行处理,但我似乎无法找到一种调整显示窗口大小的方法。我有一些水平堆叠的视频图像,但图像尺寸很小,很难看清东西。
My code is pretty simple, and along the lines of this:
我的代码非常简单,大致如下:
cv2.namedWindow("main")
....
result = np.hstack((res2, foreground))
result = np.hstack((ff, result))
cv2.imshow("main", result)
cv2.waitKey(20)
The opencv documentationstates:
在OpenCV的文件中指出:
namedWindow
flags – Flags of the window. Currently the only supported flag is CV_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.
But qt backends apparently have extra flags. I don't have a qt backend. Is there a way for me to increase the size of the images so that I can see them?
但是 qt 后端显然有额外的标志。我没有qt后端。有没有办法让我增加图像的大小以便我可以看到它们?
采纳答案by Alexey
Yes, unfortunately you can't manually resize a nameWindowwindow without Qt backend. Your options: 
是的,不幸的是,如果nameWindow没有 Qt 后端,您无法手动调整窗口大小。您的选择:
- use cv2.resizefunction to resize the image to desired size prior to displaying the image
- install OpenCV with Qt backend support and use cv2.namedWindow("main", CV_WINDOW_NORMAL)
- cv2.resize在显示图像之前使用函数将图像调整为所需的大小
- 安装带有 Qt 后端支持的 OpenCV 并使用 cv2.namedWindow("main", CV_WINDOW_NORMAL)
回答by Blutack
As per the docs, you need to create your window with autosize true.
根据文档,您需要使用 autosize true 创建窗口。
cv2.namedWindow("main", cv2.WINDOW_AUTOSIZE)
Your call to imshow will then automatically resize the window to fit your image.
您对 imshow 的调用将自动调整窗口大小以适合您的图像。
回答by rajkn90
回答by Shahrukh khan
Simply write
简单地写
cv2.namedWindow("main", cv2.WINDOW_NORMAL)
and then manually resize it to your desired size
然后手动将其调整为您想要的大小

