我有一个6400 × 3200的图像,而我的屏幕是1280x800。因此,图像需要调整大小,仅供显示。我使用的是Python和OpenCV 2.4.9。据OpenCV文档称,
如果需要显示大于屏幕分辨率的图像,则需要在显示之前调用namedWindow("",WINDOW_NORMAL)。
这就是我正在做的,但图像并不适合屏幕,只有一部分显示,因为它太大。我也尝试过使用cv2. 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
发布于 2016-02-03 17:02:15
虽然我期待一个自动的解决方案(适合于屏幕自动),调整大小也解决了这个问题。
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
发布于 2019-09-27 02:02:51
其他答案执行固定的(width, height)
调整大小。如果要在保持高宽比的同时将大小调整到特定大小,请使用以下方法
def ResizeWithAspectRatio(image, width=None, height=None, inter=cv2.INTER_AREA):
dim = None
(h, w) = image.shape[:2]
if width is None and height is None:
return image
if width is None:
r = height / float(h)
dim = (int(w * r), height)
else:
r = width / float(w)
dim = (width, int(h * r))
return cv2.resize(image, dim, interpolation=inter)
示例
image = cv2.imread('img.png')
resize = ResizeWithAspectRatio(image, width=1280) # Resize by width OR
# resize = ResizeWithAspectRatio(image, height=1280) # Resize by height
cv2.imshow('resize', resize)
cv2.waitKey()
发布于 2020-09-16 07:04:20
例如,使用这个:
cv2.namedWindow('finalImg', cv2.WINDOW_NORMAL)
cv2.imshow("finalImg",finalImg)
https://stackoverflow.com/questions/35180764
复制相似问题