Python开源工具库使用之图片去水印IOPaint

31 篇文章 0 订阅
22 篇文章 1 订阅

前言

最近发现一款去除图片水印的开源软件 IOPaint,感觉很不错,分享一下。它是一款基于 SOTA AI 模型的软件,可以实现从图片中擦除任何不需要的物体、缺陷、人,还可以替换掉(通过stable diffusion),并且还能够支持 CPU 运行(当然替换功能 stable diffusion 使用 CPU 太慢了,不建议使用),以往的深度学习软件只能使用 GPU,这款工具还可以支持 CPU 就很满足需求。并且这款工具还通过插件支持其它功能,如脸部修复、图片超分辨率、移除背景等

一、去除水印

1.1 安装部署

通过pip安装

pip install torch==2.1.2 torchvision==0.16.2
pip install iopaint

在安装完成后,通过如下命令启动,可以指定 model 路径

iopaint start --model=lama --model-dir=models --device=cpu --port=8080

执行命令后,会从 github上下载模型文件,如果下载太慢,可手动下载,并放在models\torch\hub\checkpoints下面

github模型文件:https://github.com/Sanster/models/releases/download/add_big_lama/big-lama.pt

1.2 实战

当部署完成后,可通过localhost:8080来访问web界面

去除水印

二、面部修复

2.1 安装运行

按照下面命令安装运行

pip install facexlib
pip install tb-nightly -i https://mirrors.aliyun.com/pypi/simple
pip install gfpgan
iopaint start --model=lama --model-dir=models --device=cpu --port=8080 --enable-gfpgan --gfpgan-device cpu

在运行时,会从 github 下载模型文件,同样可以手动下载放在和上面模型同样位置

github 模型文件地址:

2.2 使用

人脸修复

三、图像提升分辨率

3.1 安装

pip install realesrgan

iopaint start --model=lama --model-dir=models --device=cpu --port=8080 --enable-realesrgan --realesrgan-model RealESRGAN_x4plus --realesrgan-device cpu

github 模型文件地址:https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth

3.2 使用

超分辨率

四、移除背景

4.1 安装

pip install rembg
pip install huggingface
set HF_ENDPOINT=https://hf-mirror.com
iopaint start --model=lama --model-dir=models --device=cpu --port=8080 --enable-remove-bg

4.2 使用

移除背景

五、报错及解决方法

5.1 ERROR: Cannot install gfpgan

 from facexlib.version import __version__
    ModuleNotFoundError: No module named 'facexlib'
    During handling of the above exception, another exception occurred:
ERROR: Cannot install gfpgan==0.2.3, gfpgan==0.2.4, gfpgan==1.3.0, gfpgan==1.3.1, gfpgan==1.3.2, gfpgan==1.3.4, gfpgan==1.3.5, gfpgan==1.3.6, gfpgan==1.3.7 and gfpgan==1.3.8 because these package versions have conflicting dependencies.

原因:没有安装facexlib

解决方法:

pip install facexlib

5.2 The conflict is caused by: gfpgan 1.3.8 depends on tb-nightly

ERROR: Cannot install gfpgan==0.2.1, gfpgan==0.2.3, gfpgan==0.2.4, gfpgan==1.3.0, gfpgan==1.3.1, gfpgan==1.3.2, gfpgan==1.3.4, gfpgan==1.3.5, gfpgan==1.3.6, gfpgan==1.3.7 and gfpgan==1.3.8 because these package versions have conflicting dependencies.

The conflict is caused by:
    gfpgan 1.3.8 depends on tb-nightly
    gfpgan 1.3.7 depends on tb-nightly
    gfpgan 1.3.6 depends on tb-nightly
    gfpgan 1.3.5 depends on tb-nightly
    gfpgan 1.3.4 depends on tb-nightly
    gfpgan 1.3.2 depends on tb-nightly
    gfpgan 1.3.1 depends on tb-nightly
    gfpgan 1.3.0 depends on tb-nightly
    gfpgan 0.2.4 depends on tb-nightly
    gfpgan 0.2.3 depends on tb-nightly
    gfpgan 0.2.1 depends on tb-nightly
ERROR: ResolutionImpossible: for help

原因:依赖问题,当前源为清华源

解决方法:换源,安装 tb-nightly

pip install tb-nightly -i https://mirrors.aliyun.com/pypi/simple

5.3 Initialize RemoveBG plugin Traceback

ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x000000004842BA60>, 'Connection to huggingface.co
timed out. (connect timeout=10)')
LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested
files in the local cache. Please check your connection and try again or make sure your Internet connection is on

原因:需要从 huggingface.co 下载模型,直连超时,换个镜像

解决方法:

pip install huggingface
set HF_ENDPOINT=https://hf-mirror.com

参考

  1. https://www.iopaint.com/
  • 28
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
使用Python图片去水印,可以按照以下步骤进行操作: 1. 导入必要的:首先,需要导入一些Python来处理图像,如PIL(Python Imaging Library)或OpenCV。可以使用以下代码导入PIL: ```python from PIL import Image ``` 2. 加载图片使用PIL的`open()`函数加载要处理的图片,并将其赋值给一个变量。例如,可以使用以下代码加载名为"image.jpg"的图片: ```python image = Image.open("image.jpg") ``` 3. 去除水印:根据具体的水印情况,可以考虑以下几种方法去除水印: - 使用图像处理算法:根据水印的特征和位置,可以使用图像处理算法来去除水印。例如,可以使用边缘检测、模糊化、修复或填充等技术来消除水印的痕迹。 - 使用深度学习模型:如果水印比较复杂或难以通过传统图像处理算法去除,可以考虑使用深度学习模型。训练一个神经网络模型来识别并去除水印,或者使用预训练的模型进行水印消除。 - 使用克隆修复工具:克隆修复工具如Photoshop等,可以通过选择和复制周围区域的像素来遮盖水印。你可以使用Python的图像处理,如PIL或OpenCV,来实现类似的克隆修复功能。 4. 保存处理后的图片:处理完图片后,可以使用PIL的`save()`函数将结果保存到指定位置。例如,可以使用以下代码将处理后的图片保存为"output.jpg": ```python image.save("output.jpg") ``` 需要注意的是,针对不同的水印情况,可能需要采用不同的方法和技术来去除水印。选择合适的方法需要根据具体的水印特征和要求来决定。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aabond

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值