2

i am trying to resize the following PNG image without losing transparent background (alpha channel) using cv2.resize() function but it only shows the original image with same dimensions [![][1]][1]

the code i have written is:

import cv2

img=cv2.imread('ball.png',-1)
cv2.resize(img,(100,100))
cv2.imshow('Image',img)
cv2.waitKey(0)
user7845429
  • 103
  • 1
  • 8

1 Answers1

3

Try something like this

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