I am trying to add a transaprent logo to an existing image array. It works fine except that I lose the transparency and it is replaced in black. I think this happens when the image is resized. Here is my code:
import cv2
import numpy as np
def add_logo(array):
logo = cv2.imread("resources/logo/logo.png", 0)
logo = np.array(logo, dtype=np.uint16)
logo *= 256
scale_percent =
width = int(logo.shape[1] * scale_percent / 100)
height = int(logo.shape[0] * scale_percent / 100)
dim = (width, height)
logo = cv2.resize(logo, dim, interpolation = cv2.INTER_AREA)
#cv2.imwrite('02.png',logo)
print(array.shape, logo.shape)
x_offset = y_offset = 50
array[y_offset:y_offset+logo.shape[0],
x_offset:x_offset+logo.shape[1]] = logo
return array
imgs = get_images_from_xxxx()
edited = add_logo(imgs[0])
cv2.imwrite('01.png',edited)
I also tried this solution, but i does not apply to my context, as it it very important that the original array shape or data is not changed except for adding the logo.
This is part of the image i'm getting: but I don't need the black background as the original logo is transparent. Sorry had to crop out the logo!
And if it helps, here is a print of the array passed to add_logo, it's a numpy array:
[[3505 3514 3606 ... 4622 4781 0]
[3566 3507 3503 ... 4587 4386 0]
[3522 3503 3453 ... 4584 4434 0]
...
[3435 3428 3428 ... 3721 3779 0]
[3451 3418 3455 ... 3829 3877 0]
[ 0 0 0 ... 0 0 0]]
And the outputs of print(array.shape, logo.shape)
:
(1721, 912) (378, 304)
Any ideas are greaaaatly appreciated. :)