简体   繁体   中英

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.

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

Solved: 固定图像

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM