preamble
A few days ago, I was playing Jitterbug and found an operation to animate a portrait, which I thought was fun. I thought to myself: since python is so powerful, isn't it possible to use a python program to implement such an operation?
Haha! I myself of course do not have the ability to write such a program out, but Baidu can ah, and also very good. Baidu AI open platform provides us with a complete interface, and even the code will be thoughtful to us well written. These interfaces also support many mainstream languages are it, like Java, Python, PHP, C#, etc., we do is to call it directly.
How is the effect? Let's take a look at the comparison chart below.
Effective demonstration
The first group of ancient beauties -
The original diagram -
Rendering -
Ah ...... The Water of West Lake My Tears ...... The animeization of this picture is super perfect especially that hand, everything is good except the face!!!!
The second group of live-action cos--
The original diagram -
Rendering -
Be careful if you choose to animate your pictures~ Some are good, some are ugly! Hahaha!
Code Showcase
import requests, base64 # This function operates to obtain the access_token parameter def get_access_token(): url = '/oauth/2.0/token' data = { 'grant_type': 'client_credentials', # Fixed value 'client_id': '3j8EWb6rgg..SPY2X693LBy', # API Key of the application built after registration on the open platform 'client_secret': 'Px9KZuU0Gl...jTKktoCopnIWEiF57gf' # Secret Key of the built application } res = (url, data=data) res = () #print(res) access_token = res['access_token'] return access_token # The following code is from the API documentation, just move it over and use it. request_url = "/rest/2.0/image-process/v1/selfie_anime" f = open('', 'rb') # Open image files in binary img = base64.b64encode(()) # image to base64 format, which is required by the Baidu API documentation params = {"image":img} access_token = '24.11731cd1f0...9f9b3a930f917f3681b.2592000.1596894747.282335-21221990' request_url = request_url + "?access_token=" + get_access_token() headers = {'content-type': 'application/x-www-form-urlencoded'} response = (request_url, data=params, headers=headers) res = () # Previously we described that this request returns a dictionary, and one of the keys is image, which represents the processed image information. # Write this image information to get the final effect image. if res: f = open("", 'wb') after_img = res['image'] after_img = base64.b64decode(after_img) (after_img) ()
take note of
Find the API Key and Secret Key by first logging into the Baidu SmartCloud URL.
Baidu Intelligent Cloud
/
To this article on Python OpenCV to achieve the effect of character animation is introduced to this article, more related Python OpenCV character animation content, please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!