Use Python to quickly cut out images

Introduction to Python##

Python is a cross-platform computer programming language. It is an object-oriented dynamic type language. It was originally designed to write automated scripts (shell). With the continuous update of the version and the addition of new language features, it is increasingly used for the development of independent and large-scale projects.
Although python is a universal language that can be used to write any type of program, it is most commonly used to write the following applications

  1. Scripts-These short programs automatically perform common management tasks, such as adding users to the system, uploading files to websites, downloading web pages without using a browser, etc.

  2. Website development-As a tool for quickly creating dynamic websites, many python projects such as Django (www.djangoproject.com), Bottle (www.bottlepy.org) and Zope (www.zope.org) are very popular among developers. For example: the popular news website www.rebbit.com is developed using python.

  3. Text processing-Python provides powerful support for string and text file processing, including regular expressions and Unicode.

  4. Scientific computing-There are many excellent python scientific computing libraries on the Internet, which provide functions for statistics, mathematical calculations and graphing.

  5. Education-In view of the simplicity and practicality of python, more and more schools use it as the first programming language of instruction.

Of course, python is not the best choice for any project. Its speed is usually slower than languages such as Java, C#, C++, etc., so python will not be used to develop new operating systems.

However, when you need to minimize the time the programmer spends on the project, python is usually the best choice.

Okay, now you are on the right track. First prepare the python portal: Click me to send

The tutorials for configuring environment variables are in the above portal

Secondly install pip in the computer
Win10 click on the start menu and enter cmd to run as an administrator
Win7 press win+r and enter cmd to run as an administrator
Open cmd and enter the following code:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Enter after downloading the Pip program

sudo python get-pip.py

After the installation is complete, cmd enters pip to see if the installation is successful

Then enter in the cmd window

pip install removebg

Install the third-party package after the installation is complete
Go here remove.bg
Register with email and get API (free)

Recommend a development tool: pycharm Portal: Poke me

Finally, create a new project, create a .py file and copy the code

# Import the third-party RemoveBg package
from removebg import RemoveBg
import os
# Fill in the API parameters and error log file name in the calling method. Replace FJSLcn1KYKP4t3y5SiMmuSh3 with your own API
rmbg =RemoveBg("FJSLcn1KYKP4t3y5SiMmuSh3","./error.log")
# Specify the file output directory as the pic folder of the project directory
path = os.path.join(os.getcwd(),"pic")for pic in os.listdir(path):
 # Export the processed pictures to the pic folder
 rmbg.remove_background_from_img_file(os.path.join(path, pic))

You can quickly cut out the picture (processed within 5 seconds)
Outstanding effect

Recommended Posts

Use Python to quickly cut out images
How to learn python quickly
How to use python tuples
How to use python thread pool
Use python to query Oracle database
Use C++ to write Python3 extensions
Use python to achieve stepwise regression
How to use SQLite in Python
How to use and and or in Python
How to use PYTHON to crawl news articles
Python | So collections are so easy to use! !
Use Python to generate Douyin character videos!
Python novice learns to use the library
Use python3 to install third on ubuntu
How to get started quickly with Python
How to use the round function in python
Dry goods | Use Python to operate mysql database
How to use the zip function in Python
01. Introduction to Python
How to use the format function in python
Python uses PIL to cut and stitch pictures
Python crawler-beautifulsoup use
Use python to realize business card management system
Introduction to Python
Use python to realize the aircraft war game
Centos 6.4 python 2.6 upgrade to 2.7
Centos 6.4 python 2.6 upgrade to 2.7
Python3 external module use