Python - OpenCV - imread - 显示图像 [英] Python - OpenCV - imread - Displaying Image

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

问题描述

我目前正致力于阅读图像并将其显示在窗口中。我已成功完成此操作,但在显示图像时,窗口只允许我查看
完整图像的一部分。我尝试在加载后保存图像,并保存整个图像。所以我相当肯定它正在阅读整个图像。

I am currently working on reading an image and displaying it to a window. I have successfully done this, but upon displaying the image, the window only allows me to see a portion of the full image. I tried saving the image after loading it, and it saved the entire image. So I am fairly certain that it is reading the entire image.

imgFile = cv.imread('1.jpg')

cv.imshow('dst_rt', imgFile)
cv.waitKey(0)
cv.destroyAllWindows()

图片:

屏幕截图:

Screenshot:

推荐答案

看起来图像太大,窗口根本不适合屏幕。
使用 cv2.WINDOW_NORMAL 标志创建窗口,它将使其可伸缩。然后你可以像这样调整大小以适应你的屏幕:

Looks like the image is too big and the window simply doesn't fit the screen. Create window with the cv2.WINDOW_NORMAL flag, it will make it scalable. Then you can resize it to fit your screen like this:

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()

根据OpenCV文档 CV_WINDOW_KEEPRATIO 标志应该做同样的事情,但它没有,它的值甚至没有出现在python模块中。

According to the OpenCV documentation CV_WINDOW_KEEPRATIO flag should do the same, yet it doesn't and it's value not even presented in the python module.

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

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