opencv python,水印可以在白色背景上看到

发布于 2025-01-30 01:50:14 字数 1453 浏览 1 评论 0 原文

我试图将水印粘贴到白色背景图的图像上:

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

但是我看不到白色背景图像上的水印,我认为我必须使用 addweighteded 方法的参数。发生这种情况:

注意:水印被粘贴到右下角。

​/I.SSTATIC.NET/7AVBT.PNG“ ALT =“在此处输入图像说明”>

已解决:

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.

enter image description here

enter image description here

enter image description here

enter image description here

Solved:
Fixed image

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2025-02-06 01:50:14

问题是由 cv2.Addweaighted 的错误用法

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

引起。

如果您想要图像和水印之间的 50-50 的混合物,则应将其更改为:

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

请参阅文档: addweeighted
和用法示例: add adding(混合)两个图像使用openCV

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文