import cv2import numpy as nppath = "test2.jpg"img = cv2.imread(path)height, width, depth = img.shape[0:3]# 图片二值化处理,把[240, 240, 240]~[255, 255, 255]以外的颜色变成0thresh = cv2.inRange(img, np.array([245, 245, 245]), np.array([255, 255, 255]))# 创建形状和尺寸的结构元素kernel = np.ones((3, 3), np.uint8)# 扩张待修复区域for i in range(2, 3): hi_mask = cv2.dilate(thresh, kernel, iterations=i+1) hi_mask[int(height*0.15):int(height*0.85), 0:width] = 0 cv2.imwrite("mask2_%s.jpg" % (i + 1), hi_mask) specular = cv2.inpaint(img, hi_mask, 3, flags=cv2.INPAINT_TELEA) cv2.imwrite("result2_%s.jpg" % (i+1), specular)前提条件:水印文字是白色,出现在图片的上方或者下方
转载于:https://www.cnblogs.com/niuniuc/p/11190870.html
相关资源:Python-removewatermark根据水印模板图片自动寻找并去除图片中对应的水印