Goddess can not say the same for each photo P, so the circle of friends to open three days can be seen in Python step to solve

Hello everyone, I am a little 33 or just a just finished lunch, konjac life is wasted with brush page ...

Web content piles of silly gossip information slowly make my eyes blurred, a yawn played pounds for too many cases, at this time I saw a picture:

 

who is it! Who is the girlfriend of photos I put out!

awsl! A pair of good read ...

And so on, that bunch Stop being a hypocrite on the background of what is a ghost? ! Really could not stand it!

May be able to uncle, aunt, niece, brother of the milk is still a distant cousin classmate four-uncle, three aunt next door is not Pharaoh may be able to!

A key to download, a key rejection drawing:

Roll to roll, more afraid ...

I, on our own!

After my unremitting efforts and in line with the spirit of shameless search, painstakingly people live day, hardships, can swallow a thousand more WU, I finally found a ...

Python can be solved! I decided to share it! After no longer have to ask for help digging up!

0x00 preparation

1. You need to know a website:

https://www.remove.bg/

After opening this:

It launched a study on the effect of Python, Ruby and depth of such a tool to remove the background color, it supports call its API interface with Python, it reached to remove the background, leaving the foreground subject.

2 to register an account

Want to get the API, we must first have an account, apply for an account is very simple, to the mailbox.

If you register too much trouble, I can whisper with my API. With the API, you can only deal with every day 50 pictures, first-served basis Ah ...

3 for an API

Log in, click on the first step 'Tools & API', the second step click 'API Docs':

The third step click 'Get API Key':

The fourth step click 'Show', appeared their API:

0x01 formal matting

1 download module

Download the official website provides 'removebg' module:

pip install removebg

Cutout three lines of code implement 2:

from removebg import RemoveBg
 
rmbg = RemoveBg('dhxxxxxxxxxxxxxxxx', 'error.log') # 第一个参数是 API,第二个参数是将错误输出到日志文件
rmbg.remove_background_from_img_file('girl.jpg') # 括号内是图片地址

Image output is 'girl.jpg_no_bg.png', let's take a look at the results:

Hee hee, the effect is very good pair of ...

And it supports batch operations:

from removebg import RemoveBg
import os
 
rmbg = RemoveBg('dhxxxxxxxxxxxxxxxx', 'error.log') # 第一个参数是 API,第二个参数是将错误输出到日志文件 path = f'{os.getcwd()}/imgs' # 存储图片的文件夹位置 for img in os.listdir(path):     rmbg.remove_background_from_img_file(f'{path}/{img}') # 括号内是图片地址

Of course, if that's too much trouble to write code, he can operate directly on the site or download its client, this is no limit to the number of times!

比如在网站上,直接点击 'Upload Image' 即可操作:

或者下载客户端,支持 Windows/Mac/Linux:

虽然这种在网站直接操作或者下载客户端用起来更简单一些,但作为一个 Python 号主还是希望大家动手用代码试一下,自己实现出来,真的是飞一般的感觉!

Guess you like

Origin www.cnblogs.com/7758520lzy/p/12146515.html