如何调整从cv2.imshow()获得的窗口的大小? [英] How to resize the window obtained from cv2.imshow()?

查看:884
本文介绍了如何调整从cv2.imshow()获得的窗口的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天开始学习OpenCV,我编写了一个简短的代码来上传(不知道,如果合适的话)一个随机图像:

I started learning OpenCV today and I wrote a short code to upload (I don't know, if it's the right term) a random image:

1

它工作正常,我可以打开图像,但是我得到的是一个大窗口,除非滚动,否则看不到完整图像:

It works fine, and I can open the image, but what I get is a big window and I can't see the full image unless I scroll it:

2

所以,我想知道一种方法,可以在较短的窗口中清晰美观地查看整个图像.

So, I'd like to know a way that I could see the whole image pretty and fine in a shorter window.

推荐答案

您可以调整图像的大小并保持宽高比不变并显示它.

You can resize the image keeping the aspect ratio same and display it.

#Display image
def display(img, frameName="OpenCV Image"):
    h, w = img.shape[0:2]
    neww = 800
    newh = int(neww*(h/w))
    img = cv2.resize(img, (neww, newh))
    cv2.imshow(frameName, img)
    cv2.waitKey(0)

这篇关于如何调整从cv2.imshow()获得的窗口的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆