Appearance
使用第三方模块
python之所以使用广泛,是因为有开发者写好了大量的模块,我们可以很方便的来使用。使用这些模块也很简单,只需要两步。
- 安装模块
在终端窗口(windows的cmd或者Pycharm的终端)中,输入以下指令:
pip install 模块名称
下面是安装抠图模块的操作:
pip install rembg
- 使用模块
下面是使用抠图模块进行抠图的代码:
python
from rembg import remove
from PIL import Image
# 需要抠图的图片
input_path = r"C:\Users\Administrator\Pictures\130406-20220530084101925-1730394191.png"
# 抠图后保存的文件
output_path = r"C:\Users\Administrator\Pictures\130406-20220530084101925-1730394191-remove.png"
# 加载图片
inp = Image.open(input_path)
# 执行抠图
output = remove(inp)
# 保存抠图后的图片
output.save(output_path)