OpenCV和Python – 图像太大而无法显示

我的图像是6400×3200,而我的屏幕是1280 x 800.因此,图像需要调整大小才能显示.我正在使用Python和OpenCV 2.4.9.
根据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.

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

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

解决方法:

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

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
上一篇:Python+OpenCV实现图像特定区域宽度测量


下一篇:python – 在xaxis中的日期,用于impow的matplotlib图