OpenCV &Python - 图像太大而无法显示 [英] OpenCV & Python - Image too big to display

查看:105
本文介绍了OpenCV &Python - 图像太大而无法显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 6400 × 3200 的图像,而我的屏幕是 1280 x 800.因此,图像需要调整大小以仅显示.我正在使用 Python 和 OpenCV 2.4.9.根据OpenCV Documentation,><块引用>

如果您需要显示大于屏幕分辨率的图像,则需要在 imshow 之前调用 namedWindow("", WINDOW_NORMAL).

这就是我正在做的,但图像不适合屏幕,只显示了一部分,因为它太大了.我也试过 cv2.resizeWindow,但它没有任何区别.

导入 cv2cv2.namedWindow("output", cv2.WINDOW_NORMAL) # 创建尺寸自由的窗口# cv2.resizeWindow("output", 400, 300) # 调整窗口到指定尺寸im = cv2.imread("earth.jpg") # 读取图片cv2.imshow("output", im) # 显示图片cv2.waitKey(0) # 无限显示图像直到任何按键

解决方案

虽然我期待一个自动解决方案(自动适应屏幕),调整大小也解决了这个问题.

导入 cv2cv2.namedWindow("output", cv2.WINDOW_NORMAL) # 创建具有尺寸自由的窗口im = cv2.imread("earth.jpg") # 读取图片imS = cv2.resize(im, (960, 540)) # 调整图像大小cv2.imshow("output", imS) # 显示图片cv2.waitKey(0) # 无限显示图像直到任何按键

I have an image that is 6400 × 3200, while my screen is 1280 x 800. Therefore, the image needs to be resized for display only. I am using Python and OpenCV 2.4.9. According to OpenCV Documentation,

If you need to show an image that is bigger than the screen resolution, you will need to call namedWindow("", WINDOW_NORMAL) before the imshow.

That is what I am doing, but the image is not fitted to the screen, only a portion is shown because it's too big. I've also tried with cv2.resizeWindow, but it doesn't make any difference.

import cv2
cv2.namedWindow("output", cv2.WINDOW_NORMAL)        # Create window with freedom of dimensions
# cv2.resizeWindow("output", 400, 300)              # Resize window to specified dimensions
im = cv2.imread("earth.jpg")                        # Read image
cv2.imshow("output", im)                            # Show image
cv2.waitKey(0)                                      # Display the image infinitely until any keypress

解决方案

Although I was expecting an automatic solution (fitting to the screen automatically), resizing solves the problem as well.

import cv2
cv2.namedWindow("output", cv2.WINDOW_NORMAL)    # Create window with freedom of dimensions
im = cv2.imread("earth.jpg")                    # Read image
imS = cv2.resize(im, (960, 540))                # Resize image
cv2.imshow("output", imS)                       # Show image
cv2.waitKey(0)                                  # Display the image infinitely until any keypress

这篇关于OpenCV &amp;Python - 图像太大而无法显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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