python opencv显示图片_Python - OpenCV - imread - 显示图像

1586010002-jmsa.png

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

Image:

ug90J.jpg

Screenshot:

qsJuF.jpg

解决方案

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

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值