
windows去水印腳本

以下是一個基于Python的Windows去水印腳本示例,使用OpenCV庫處理靜態圖像水印。請根據實際需求調整參數:```pythonimport cv2import...
以下是一個基于Python的Windows去水印腳本示例,使用OpenCV庫處理靜態圖像水印。請根據實際需求調整參數:
```python
import cv2
import os
def remove_watermark(input_path, output_path, watermark_pos="bottom_right", threshold=0.5):
"""
去除圖片水印的函數
參數:
input_path: 輸入圖片路徑
output_path: 輸出路徑(默認同目錄watermark_removed_)
watermark_pos: 水印位置(可選:top_left, top_right, bottom_left, bottom_right)
threshold: 水印檢測閾值(0-1)
"""
讀取圖片
img = cv2.imread(input_path)
if img is None:
raise ValueError("無法讀取圖片文件")
水印檢測區域(根據位置調整)h, w = img.shape[:2]
if watermark_pos == "top_left":
y_start, x_start = 0, 0
elif watermark_pos == "top_right":
y_start, x_start = 0, w//4
elif watermark_pos == "bottom_left":
y_start, x_start = h//4, 0
elif watermark_pos == "bottom_right":
y_start, x_start = h//4, w//4
else:
raise ValueError("無效的watermark_pos值")
提取水印區域
watermark = img[y_start:y_start+50, x_start:x_start+50]
watermark_avg = cv2.mean(watermark)[0]
檢測是否為水印(根據均值閾值)
if watermark_avg > threshold:
遮蓋水印區域
img[y_start:y_start+50, x_start:x_start+50] = 0
保存結果
output_dir = os.path.dirname(output_path) or os.path.dirname(input_path)
os.makedirs(output_dir, exist_ok=True)
cv2.imwrite(os.path.join(output_dir, f"watermark_removed_{os.path.basename(input_path)
本文鏈接:http://www.wzyaohuidianqi.cn/gong/424377.html
上一篇:蘋果電腦ps去水印快捷鍵
下一篇:神奇去水印,神奇去水印app
