Python/Basic/chick_python_exam/Unit1_basic/EXEcode/imgWatermark.py
2024-06-27 15:41:10 +08:00

24 lines
861 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'''
Program: imgWatermark.py (Report comments/bugs to chikh@yuntech.edu.tw)
Function: 輸入的影像上加入浮水印,本例加入一段文字作示範
'''
import cv2 #引入OpenCV影像處理的相關套件
img = cv2.imread("YunTech.jpg") # 讀取影像
#----- 設定要添加的文字:開始 -----#
text = 'YunTech Campus'
position = (10,40) #文字左下角的座標
font = cv2.FONT_HERSHEY_COMPLEX
fontScale = 1 #指定文字大小的比例
color = (0,255,0) #以RGB三原色設定綠色文字RGB色表可見 https://bit.ly/2ymSOJF
thickness = 2 #文字的線寬
#----- 設定要添加的文字:結束 -----#
cv2.putText(img,text,position,font,fontScale,color,thickness) #在影像上添加文字
cv2.imshow("Watermarked Image",img) #顯示影像
cv2.waitKey(0) #等候按任意鍵
cv2.destroyAllWindows() #關閉所有視窗