为了提高抠图效率,我使用了Python工具

背景

因为自己使用 Photoshop 抠图不熟练、抠不好,效率还低,所以就使用了 Python 工具来帮忙抠图。

原图:

Python 抠出的图片:

实现步骤

1、安装 Python 抠图依赖模块。

from rembg import remove, new_session
from pathlib import Path

2、开始抠图。

from pathlib import Path
from rembg import remove, new_session

session = new_session()

for file in Path('input').glob('*.jpg'):
    # 待处理的文件路径
    input_path = str(file)
    # 输出处理好的文件路径
    output_path = "output/" + file.stem + ".out.jpg"

    with open(input_path, 'rb') as i:
        with open(output_path, 'wb') as o:
            input = i.read()
            output = remove(input, session=session)
            o.write(output)
            print(f'{file.stem}.out.jpg 抠图成功')

总结

实现步骤其实挺简单的,需要注意的是,首次运行代码的时候会去下载 u2net.onnx 这个文件会比较耗时,需要耐心等待,有了这个工具就可以愉快的抠图啦。

展开阅读全文

页面更新:2024-05-15

标签:效率   工具   原图   路径   模块   步骤   愉快   不好   背景   文件

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号

Top