# coding:utf-8
# @Email: wangguisen@donews.com
# @Time: 2023/4/21 10:07
# @File: utils.py
'''
'''
import cv2
import PIL
from PIL import Image
import numpy as np
from watermarker.marker import add_mark, im_add_mark
import matplotlib.pyplot as plt
# PIL Image转换成OpenCV格式
def PILImageToCV(imagePath):
img = Image.open(imagePath)
plt.imshow(img)
img = cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)
plt.imshow(img)
plt.show()
# OpenCV图片转换为PIL image
def CVImageToPIL(imagePath=None, img=None):
# 自己改改
# img = cv2.imread(imagePath)
# plt.imshow(img)
img2 = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
# plt.imshow(img2)
# plt.show()
return img2
img = cv2.imread('./imgs/res_ori_test.jpg')
# 创建毛玻璃特效
# 参数2:高斯核的宽和高(建议是奇数)
# 参数3:x和y轴的标准差
dst = cv2.GaussianBlur(img, (99, 99), 333)
# cv2.imshow('dst', dst)
# add_mark(file="test1.jpg", out="add_mark_test1.jpg", mark="Python", opacity=0.2, angle=30, space=30)
dst = CVImageToPIL(img=dst)
image = im_add_mark(dst, text="Python", color="#8B8B1B", size=50, opacity=0.3, space=75, angle=30)
image.save("./imgs/add_mark_test1.png")
# add_mark(dst, out="./imgs/add_mark_test1.jpg", mark="Python", opacity=0.2, angle=30, space=30)
# cv2.waitKey()
文章来源地址https://www.toymoban.com/news/detail-611440.html
文章来源:https://www.toymoban.com/news/detail-611440.html
到了这里,关于OpenCV实现高斯模糊加水印的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!