如何在opencv2 python中调整窗口大小 [英] How to resize window in opencv2 python
问题描述
我正在使用带有摄像头的opencv 2.我可以获取视频流并对其进行处理,但是似乎无法找到一种调整显示窗口大小的方法.我有一些视频图像水平堆叠,但是图像尺寸很小,很难看清东西.
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.
我的代码非常简单,大致如下:
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)
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.
但是qt后端显然具有额外的标志.我没有qt后端.我有办法增加图像的大小以便看到它们吗?
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后端,您无法手动调整nameWindow
窗口的大小.您的选择:
Yes, unfortunately you can't manually resize a nameWindow
window without Qt backend. Your options:
- 在显示图像之前,使用
cv2.resize
函数将图像调整为所需尺寸 - 安装具有Qt后端支持的OpenCV并使用
cv2.namedWindow("main", CV_WINDOW_NORMAL)
- use
cv2.resize
function 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)
这篇关于如何在opencv2 python中调整窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!