OpenCV Python,白底看不到水印

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

我正在尝试将我的水印粘贴到白底图片中:

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

但是我在白底图像上看不到水印,我想我必须使用 addWeighted 方法的参数。发生这种情况:

注意:水印贴在右下角。

已解决:

问题是由于 cv2.addWeighted 的不正确使用引起的,在这行:

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

第二个参数(你设置为1)是第一张图片的权重。

如果你想在图像和水印之间混合 50-50,你应该将其更改为:

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

查看文档:addWeighted
以及一个用法示例:Adding (blending) two images using OpenCV.