6

Python 图片去除图片水印的问题

 3 years ago
source link: https://www.v2ex.com/t/797099
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Python

Python 图片去除图片水印的问题

  chenqh · 2 天前 · 367 次点击

def remove_water_footer(path, newPath):
    """
    去除水印
    """
    # https://zhuanlan.zhihu.com/p/138169619
    img=cv2.imread(path,1)
    hight,width,depth=img.shape[0:3]
    height = hight

    #截取
    # cropped = img[int(hight*0.8):hight, int(width*0.7):width]  # 裁剪坐标为[y0:y1, x0:x1]
    #cropped = cropped_img(img,
    #height=height,
    #width=width)
    cropped_size = cropped_img_size(
    height=height,
    width=width)
    cropped = img[cropped_size[0][0]: cropped_size[0][1], cropped_size[1][0]: cropped_size[1][1]]
    cv2.imwrite(newPath, cropped)
    imgSY = cv2.imread(newPath,1)

    #图片二值化处理,把[200,200,200]-[250,250,250]以外的颜色变成 0
    # thresh = cv2.inRange(imgSY,np.array([200,200,200]),np.array([250,250,250]))
    thresh = cv2.inRange(imgSY,np.array([24, 43, 48]),np.array([160,180,190]))
    #创建形状和尺寸的结构元素
    kernel = np.ones((3,3),np.uint8)
    #扩展待修复区域
    hi_mask = cv2.dilate(thresh,kernel,iterations=10)
    specular = cv2.inpaint(imgSY,hi_mask,5,flags=cv2.INPAINT_TELEA)
    cv2.imwrite(newPath, specular)

    #覆盖图片
    imgSY = Image.open(newPath)
    img = Image.open(path)
    # img.paste(imgSY, (int(width*0.7),int(hight*0.8),width,hight))
    img.paste(imgSY, (cropped_size[1][0],cropped_size[0][0],cropped_size[1][1],cropped_size[0][1]))
    img.save(newPath)
    logger.info("去除水印: `{}` => `{}`".format(path, newPath))

我在网上搜的,但是这个样子会留下背景版,如果吧整个水印都删除呢,

也就是指定区域的部分都删除,这种效果该怎么做呢?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK