OpenCV Python, watermark can't be seen on white backgrounds

I am trying to paste my watermark to white-backgrounded image:

        watermark = cv2.imread(watermark_path)
        watermark_ratio = round(image.shape[1]/8)       # calculating the ratio 
        resized_watermark = cv2.resize(watermark, (watermark_ratio, round(watermark_ratio/2)), interpolation = cv2.INTER_AREA)    # resizing watermark size

        h_logo, w_logo, _ = resized_watermark.shape
        h_img, w_img, _ = image.shape
        top_y = h_img - h_logo
        left_x = w_img - w_logo
        bottom_y = h_img
        right_x = w_img

        destination = image[top_y:bottom_y, left_x:right_x]
        result = cv2.addWeighted(destination, 1, resized_watermark, 0.5, 0)     # pasting watermark on original image
        image[top_y:bottom_y, left_x:right_x] = result

        cv2.imwrite(save_path, image)          # saving watermarked the image

But I can’t see watermark on white-backgrounded images, and I think I have to play with parameters of addWeighted method. This happens:

Note: Watermark is pasted to the bottom right corner.

Watermark

Image with watermark (some life signs from watermark)

Image with watermark #2

Image with watermark on darker background

>Solution :

The problem is caused by an incorrect usage of cv2.addWeighted, in thie line:

result = cv2.addWeighted(destination, 1, resized_watermark, 0.5, 0)

The 2nd parameter (you set to 1) is the weight of the first image.

If you want a blend of 50-50 between the image and the watermark, you should change it to:

result = cv2.addWeighted(destination, 0.5, resized_watermark, 0.5, 0)

See the documentation: addWeighted.
And a usage example: Adding (blending) two images using OpenCV.

Leave a Reply