Sin*_*rde 29 python opencv image imshow
我目前正致力于阅读图像并将其显示在窗口中.我已成功完成此操作,但在显示图像时,窗口只允许我查看完整图像的一部分.我尝试在加载后保存图像,并保存整个图像.所以我相当肯定它正在阅读整个图像.
imgFile = cv.imread('1.jpg')
cv.imshow('dst_rt', imgFile)
cv.waitKey(0)
cv.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
图片:

截图:

Igo*_*ato 33
看起来图像太大,窗口根本不适合屏幕.使用cv2.WINDOW_NORMAL标志创建窗口,它将使其可伸缩.然后你可以调整它以适应你的屏幕,如下所示:
from __future__ import division
import cv2
img = cv2.imread('1.jpg')
screen_res = 1280, 720
scale_width = screen_res[0] / img.shape[1]
scale_height = screen_res[1] / img.shape[0]
scale = min(scale_width, scale_height)
window_width = int(img.shape[1] * scale)
window_height = int(img.shape[0] * scale)
cv2.namedWindow('dst_rt', cv2.WINDOW_NORMAL)
cv2.resizeWindow('dst_rt', window_width, window_height)
cv2.imshow('dst_rt', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
根据OpenCV文档 CV_WINDOW_KEEPRATIO标志应该做同样的事情,但它没有,它的价值甚至没有在python模块中呈现.