# 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()