如何在opencv2 python中调整窗口大小

Bak*_*Bak 13 python opencv

我正在使用带网络摄像头的opencv 2.我可以获得视频流并对其进行处理,但我似乎无法想出一种调整显示窗口大小的方法.我有一些水平堆叠的视频图像,但图像尺寸非常小,很难看到东西.

我的代码很简单,按照以下方式:

cv2.namedWindow("main")

....

result = np.hstack((res2, foreground))
result = np.hstack((ff, result))

cv2.imshow("main", result)
cv2.waitKey(20)
Run Code Online (Sandbox Code Playgroud)

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.
Run Code Online (Sandbox Code Playgroud)

但qt后端显然有额外的标志.我没有qt后端.有没有办法让我增加图像的大小,以便我可以看到它们?

Ale*_*xey 14

是的,遗憾的是,如果nameWindow没有Qt后端,您无法手动调整窗口大小.你的选择:

  • 使用cv2.resize函数在显示图像之前将图像大小调整为所需大小
  • 安装具有Qt后端支持和使用的OpenCV cv2.namedWindow("main", CV_WINDOW_NORMAL)

  • 如何将图像添加到窗口? (3认同)

小智 12

简单写一下

cv2.namedWindow("main", cv2.WINDOW_NORMAL)
Run Code Online (Sandbox Code Playgroud)

然后手动将其调整为所需大小

  • 在下一行: cv2.resizeWindow('image', 900, 900) (4认同)

raj*_*n90 5

您可以WINDOW_NORMAL在调用namedWindow函数时使用该标志,如下所示。这将允许您调整窗口大小。

namedWindow("Image", WINDOW_NORMAL);
Run Code Online (Sandbox Code Playgroud)

检查此处namedWindow记录的功能