如何调整PNG图片的OpenCV中的蟒蛇? [重复]

问题描述 投票:1回答:1

这个问题已经在这里有一个答案:

我试图调整以下PNG图像而不使用cv2.resize()功能失去透明的背景(alpha通道),但它仅示出了具有相同尺寸的原始图像[![] [1] [1]

我写的代码是:

import cv2

img=cv2.imread('ball.png',-1)
cv2.resize(img,(100,100))
cv2.imshow('Image',img)
cv2.waitKey(0)
python opencv image-processing image-resizing
1个回答
2
投票

尝试这样的事情

import cv2

img = cv2.imread('/home/img/python.png', cv2.IMREAD_UNCHANGED)

print('Original Dimensions : ',img.shape)

width = 350
height = 450
dim = (width, height)

# resize image
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)

print('Resized Dimensions : ',resized.shape)

cv2.imshow("Resized image", resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
© www.soinside.com 2019 - 2024. All rights reserved.