opencv python,水印可以在白色背景上看到
我试图将水印粘贴到白色背景图的图像上:
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 =“在此处输入图像说明”>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是由
cv2.Addweaighted
的错误用法引起。
如果您想要图像和水印之间的 50-50 的混合物,则应将其更改为:
请参阅文档:
addweeighted
。和用法示例: add adding(混合)两个图像使用openCV 。
The problem is caused by an incorrect usage of
cv2.addWeighted
, in thie line: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:
See the documentation:
addWeighted
.And a usage example: Adding (blending) two images using OpenCV.