Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Python OpenCV to realize the effect of character animation

Shulou Source: shulou.com Published: 2022-06-02 02:42:21 09月15日 Update

This article mainly introduces how to use Python OpenCV to achieve character animation effect, the article is very detailed, has a certain reference value, interested friends must read it!

effect display

The first group of ancient beauties

artwork

renderings

Ah... West Lake water my tears... This cartoon is super perfect, especially the hand, except for the face everything is fine!!!

The second group of real cos

artwork

renderings

If you choose pictures to be animated, be careful ~ some are good, some are still quite ugly! hahaha

The code shows import requests, base64#This function operates to get the access_token parameter def get_access_token(): url = 'https://aip.baidubce.com/oauth/2.0/token' data = { 'grant_type':'client_identities',#fixed value 'client_id': '3j8EWb6rgg.. SPY2X693LBy', #API Key for apps built after registration on open platforms 'client_secret': 'Px9KZuU0Gl... jTKktoCopnIWEiF57gf' #Secret Key of built app } res = requests.post(url, data=data) res = res.json() #print(res) access_token = res['access_token'] return access_token #The code below is the code in the API document, and you can use it directly. request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime"f = open('zhao.jpg', 'rb') #Open image file img = base64.b64encode(f.read ()) #Convert image to base64 format, which is required in 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 = requests.post (request_url, data=params, headers=headers)res = response.json()#We described earlier that this request returns a dictionary, one of the keys is image, representing the processed image information.# Write this image information to get the final effect. if res: f = open("kouzhao4.jpg", 'wb') after_img = res['image'] after_img = base64.b64decode(after_img) f.write(after_img) f.close()

note

Find API Key and Secret Key First login Baidu intelligent cloud URL.

The above is all the content of this article "How to use Python OpenCV to achieve character animation effects", thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

Tags: Effect animation code image effect character information content original picture picture that is document article application binary representative value interest function parameter Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Information Docker MariaDB Redmi