简体   繁体   English

如何使用 Python opencv 以 100% 缩放显示非常小的图像

[英]How to display very small image with 100% zoom with Python opencv

I just wanted to display a small simple image.我只是想显示一个简单的小图像。

import numpy as np
import cv2
a = np.zeros([64, 64], np.float32)
a[12, 31] = 1
cv2.imshow('test', a)
cv2.waitKey(0)

结果图像:这里有两个点

I just add one dot, but two dots are shown.我只添加一个点,但显示了两个点。

The problem is caused by the zoom rate.问题是由缩放率引起的。 I checked the display image size is (71, 71).我检查了显示图像大小是 (71, 71)。 How can I display this image correctly?如何正确显示此图像?

Thank you for your wisdom.谢谢你的智慧。


Environment:环境:

Ubuntu 18.04.2 LTS
Python 3.6.8
opencv-python (4.1.0.25)

additional:额外的:

结果图像:这里有两个点

When I pull down my mouse's wheel, I can see the message that 'Zoom:100%'.当我拉下鼠标滚轮时,我可以看到“缩放:100%”的消息。 But actually, the zoom rate is not 100%.但实际上,缩放率并不是 100%。 TWO DOTS are still shown and the displayed image size is (71, 71).仍然显示两个点,显示的图像尺寸为 (71, 71)。

cv2.resizeWindow doesn't work. cv2.resizeWindow 不起作用。


addition:添加:

结果图像:这里有两个点

When I ran same code on Windows 10, I could see correct display.当我在 Windows 10 上运行相同的代码时,我可以看到正确的显示。 It is exact 100% zoom rate.这是精确的 100% 缩放率。

You can always use cv2.resize() to change the size of the image to what you want.您始终可以使用 cv2.resize() 将图像的大小更改为您想要的大小。

height = 64
dim = (width, height)

resized = cv2.resize(a, dim, interpolation = cv2.INTER_AREA)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM