[英]opencv cv2.imshow automatically add padding to small image
I try to use cv2.imshow() to display images, however I find that the result is padded with blank automatically. 我尝试使用cv2.imshow()显示图像,但是我发现结果自动用空白填充。 The code I use is as following: 我使用的代码如下:
import cv2
if __name__ == '__main__':
img = cv2.imread('test2.png')
cv2.imshow('dafasf', img)
key = cv2.waitKey(0)
if key == 27: # ESC
cv2.destroyAllWindows()
By default imshow
creates window object with WINDOW_AUTOSIZE
attribute. 默认情况下, imshow
创建具有WINDOW_AUTOSIZE
属性的窗口对象。 It means that window size is determined by some frontend (GUI) which OpenCV was compiled with. 这意味着窗口大小由编译OpenCV的某些前端(GUI)确定。
Your image are not actually changed, it is just displaying issue. 您的图片实际上没有更改,只是显示问题。
If you want to manually control window attributes, you can try to create namedWindow
with your attributes before imshow
call, ie something like this: 如果要手动控制窗口属性,可以尝试在imshow
调用之前使用属性创建namedWindow
,例如:
cv2.namedWindow("window name", cv2.WINDOW_NORMAL)
cv2.imshow("window name", img)
According to documentation there are 3 attributes for window displaying ( WINDOW_NORMAL
, WINDOW_AUTOSIZE
and WINDOW_OPENGL
), but with the following simple snippet you can determine your actually supported values (in my version I see WINDOW_FREERATIO
, WINDOW_FULLSCREEN
, WINDOW_AUTOSIZE
, WINDOW_NORMAL
, WINDOW_KEEPRATIO
and WINDOW_OPENGL
): 根据文件有3个属性的窗口显示( WINDOW_NORMAL
, WINDOW_AUTOSIZE
和WINDOW_OPENGL
),但具有下列简单的代码片段,你可以决定你的实际支持的值(在我的版本我看到WINDOW_FREERATIO
, WINDOW_FULLSCREEN
, WINDOW_AUTOSIZE
, WINDOW_NORMAL
, WINDOW_KEEPRATIO
和WINDOW_OPENGL
):
[i for i in list(cv2.__dict__.keys()) if i[:6] == 'WINDOW']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.