|
- import cv2
- import numpy as np
- # 中文乱码,不支持中文
- img=cv2.imread("C:\\Users\\chenyukun\\Pictures\\Camera Roll\\a.jpg") # 导入我们需要添加水印的图片
- # RGB_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
- RGB_img = img
- blank_img = np.zeros(shape=(RGB_img.shape[0],RGB_img.shape[1],3), dtype=np.uint8)
- font = cv2.FONT_HERSHEY_SIMPLEX
- # 添加水印的文字内容
- cv2.putText(blank_img,text='Learn Python',org=(40, 90),
- fontFace=font,fontScale= 2,
- color=(255,0,0),thickness=10,lineType=cv2.LINE_4)
- blended = cv2.addWeighted(src1=RGB_img, alpha=0.7,
- src2=blank_img, beta=1, gamma = 2)
- cv2.imshow("Watermarked Image", blended)
- cv2.imwrite("watermarked.jpg", blended)
- cv2.waitKey(100000)
- cv2.destroyAllWindows()
|