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

2021-08-20 20:43:59 +08:00
 chenqh

代码


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))

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

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

1590 次点击
所在节点    Python
11 条回复
julyclyde
2021-08-23 12:41:34 +08:00
你这个需求不符合信息论
chenqh
2021-08-23 12:46:16 +08:00
@julyclyde 那谢谢了, 因为软件可以,我也以为 py 直接就可以, 可能需要算法吧, 那我还是用软件吧
julyclyde
2021-08-23 13:52:12 +08:00
@chenqh 用算法也不可能
chenqh
2021-08-23 15:04:37 +08:00
@julyclyde 那那些去水印的软件怎么做的?
Carry0317
2021-08-23 15:49:02 +08:00
你用的啥软件
chenqh
2021-08-23 15:53:16 +08:00
@Carry0317 BatchInpaint64
Carry0317
2021-08-23 16:00:51 +08:00
@chenqh 还是用算法吧
chenqh
2021-08-23 16:10:19 +08:00
@Carry0317 我不会呀, 我很菜的
julyclyde
2021-08-24 11:05:24 +08:00
@chenqh 用旁边的颜色去涂抹被删除的水印
chenqh
2021-08-24 12:59:27 +08:00
@julyclyde 有代码吗?大佬?
imn1
2021-08-26 14:45:31 +08:00
github 搜 watermark,有 py+opencv 的,但我没用过

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/797099

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX