preface

A few days ago when I played Douyin, I found a cartoon operation and felt it was very interesting. I thought to myself: Python is so powerful, no

Is it possible to use a Python program to do this?

Ha ha! I certainly do not have this ability to write such an awesome program, but Baidu can ah, and also very good

To use. Baidu AI open platform to provide us with a complete interface, and even close to the code has been written for us. These interfaces are still supported

With many mainstream languages, such as Java, Python, PHP, C#, etc., all we can do is call it directly. The effect how

The sample? Let’s take a look at the comparison below.

Effect display:

The second group of ancient beauty —

The original image,

Rendering –

Ah… The water of west Lake my tears…… The animation is super perfect especially the hand, everything is fine except the face!!

The third group of human cosplay —

Original graph – effect graph – we choose the words of animation carefully ha ~ some very good, some or quite ugly! Ha, ha, ha

Code display:

Def get_access_token() def get_access_token() def get_access_token() def get_access_token() Url = 'https://aip.baidubce.com/oauth/2.0/token' data = {' grant_type ':' client_credentials' # 'client_id' fixed value: '3j8EWb6rgg.. SPY2X693LBy', # API Key 'client_secret': 'Px9KZuU0Gl... JTKktoCopnIWEiF57gf '# request. Post (url, Data =data) res = res.json() #print(res) access_token = res['access_token'] return access_token # Just bring it in and use it. Request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime" f = open (' zhao. JPG, Img = base64. B64encode (f.read()) Params = {"image":img} access_token = '24.11731cd1f0... 9 f9b3a930f917f3681b. 2592000.1596894747.282335-21221990 'request_url = request_url + "? access_token=" + get_access_token() headers = {'content-type': 'application/x-www-form-urlencoded'} response = requests.post(request_url, data=params, Headers =headers) res = response.json() # this request returns a dictionary, and one of the keys is image. # Write this image information to get the final effect picture. if res: f = open("kouzhao4.jpg", 'wb') after_img = res['image'] after_img = base64.b64decode(after_img) f.write(after_img) f.close()Copy the code

Note: To search for API keys and Secret keys, first log in the website of Baidu Intelligent Cloud.

Baidu Intelligent Cloud

login.bce.baidu.com/

summary

Everyone code has a problem or need to complete the material project what remember to find me ha ~ welcome everyone!

Source code base —

Private letter xiaobian 06 or click on this line of blue font can be free ha!

🎉 Recommended reading —

Project 1.0 Cartoon head

【Opencv Combat 】 How to quickly Get your own avatar? Amazing — Girlfriend’s profile picture was finally found

Project 1.1 Animated characters

Who says the second dimension is far away from us? Python effects are all over the web, and it turns out to be the key technology.

Item 1.4 Automatic vehicle detection violation

Heard clap somebody else illegal monthly into 100,000? Well, I wrote an automatic detection system to check if the car is illegal

Item 1.5 AI detection of plagiarism small scripts

Classmate: You have been caught by AI for cheating in your homework. Python made a small script for AI detection and plagiarism.

🎄 Article summary —

The article summary | Python 1.0-2021 | has continuously updated, direct look at this article is enough

More content + source code in the article summary oh!! Welcome to read ~)