V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
chenqh
V2EX  ›  Python

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

  •  
  •   chenqh · 2021-08-20 20:43:59 +08:00 · 1562 次点击
    这是一个创建于 950 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码

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

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

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

    11 条回复    2021-08-26 14:45:31 +08:00
    julyclyde
        1
    julyclyde  
       2021-08-23 12:41:34 +08:00   ❤️ 1
    你这个需求不符合信息论
    chenqh
        2
    chenqh  
    OP
       2021-08-23 12:46:16 +08:00
    @julyclyde 那谢谢了, 因为软件可以,我也以为 py 直接就可以, 可能需要算法吧, 那我还是用软件吧
    julyclyde
        3
    julyclyde  
       2021-08-23 13:52:12 +08:00
    @chenqh 用算法也不可能
    chenqh
        4
    chenqh  
    OP
       2021-08-23 15:04:37 +08:00
    @julyclyde 那那些去水印的软件怎么做的?
    Carry0317
        5
    Carry0317  
       2021-08-23 15:49:02 +08:00
    你用的啥软件
    chenqh
        6
    chenqh  
    OP
       2021-08-23 15:53:16 +08:00
    @Carry0317 BatchInpaint64
    Carry0317
        7
    Carry0317  
       2021-08-23 16:00:51 +08:00
    @chenqh 还是用算法吧
    chenqh
        8
    chenqh  
    OP
       2021-08-23 16:10:19 +08:00
    @Carry0317 我不会呀, 我很菜的
    julyclyde
        9
    julyclyde  
       2021-08-24 11:05:24 +08:00
    @chenqh 用旁边的颜色去涂抹被删除的水印
    chenqh
        10
    chenqh  
    OP
       2021-08-24 12:59:27 +08:00
    @julyclyde 有代码吗?大佬?
    imn1
        11
    imn1  
       2021-08-26 14:45:31 +08:00
    github 搜 watermark,有 py+opencv 的,但我没用过
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3222 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:37 · PVG 19:37 · LAX 04:37 · JFK 07:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.