因为自己使用 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
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号