import removebg import os import shutil rmbg = removebg.RemoveBg("3EmmeEPcPRyRR41FPJ1se7H7", "error.log") r = r"C:\Users\Lenovo\PycharmProjects\untitled1\project\ai_ps\raw_img2" new_folder = os.path.join(r, "抠图") def batch_removebg(): fileList = os.listdir(r) for f in fileList: suffix = os.path.splitext(f)[-1] if suffix == ".png" or suffix == ".jpg": rmbg.remove_background_from_img_file(os.path.join(r, f)) def make_new_folder(): if not os.path.exists(new_folder): os.makedirs(new_folder) def copy_new_pic(): fileList = os.listdir(r) for f in fileList: if f.count("no_bg") > 0: print(os.path.join(r, f)) shutil.move(os.path.join(r, f), new_folder)
# -*- coding:utf-8 -*- """ @Author: Felix @File: 去除图片背景(抠图).py @Desc: @Create: 2020/09/21 14:52 """ import removebg rmbg = removebg.RemoveBg(api_key="TSoFQ21EhJF634VtkEuLWX92", error_log_file="./File/Error_log_rmbg.txt") rmbg.remove_background_from_img_file("./images/AIFaceImg/match_1.jpg")
import removebg rmbg = removebg.RemoveBg("2FPyYH9eRvs5T6Vh8Wqf7gmL", "error.log") rmbg.remove_background_from_img_file( r"C:\Users\Lenovo\PycharmProjects\untitled1\project\ai_ps\ai_ps_test_img2.jpg" )
import removebg from PIL import Image if __name__ == '__main__': rmbg = removebg.RemoveBg("8g7Fy3Q4N9uwZHmQFUz718aa", "error.log") out_path = r"E:\abc.jpg" rmbg.remove_background_from_img_file(img_file_path=out_path, bg_color='red') img = Image.open(out_path + "_no_bg.png") i = img.resize((358, 441), Image.ANTIALIAS) i.save(r"E:\bbb.png", quality=0)