Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the tips for Python to repair and color old photos?

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you Python to achieve the old photo repair color tips, I believe that most people do not know much, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Text

Baidu AI open platform "black-and-white image color", this is highly recommended, 20 lines of code can be done black-and-white photos to color!

The first step: search Baidu AI into the official website to find: open ability-"image technology."

Step 2: find the black-and-white image and color it.

Step 3: you need to register as a Baidu developer, create applications, get API Key and Secret Key, then get access_token, and input black-and-white images to get Base64 coding of color images. Then convert the Base64 encoding string into a picture!

Attached code: import base64import requests # client_id is the AK obtained on the official website Client_secret for the official website to obtain SKhost = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id= your AK&client_secret= your SK'response = requests.get (host) if response: print (response.json ()) # black-and-white image color request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/colourize"# binary open picture file f = open (' test.png') 'rb') img = base64.b64encode (f.read ()) params = {"image": img} access_token= response.json () [' access_token'] request_url = request_url + "? access_token=" + access_tokenheaders = {'content-type':' application/x-www-form-urlencoded'} response = requests.post (request_url, data=params) Headers=headers) if response: print (response.json ()) # base64 Encoding to Picture img = base64.b64decode (response.json () ['image']) file = open (' result.jpg', 'wb') file.write (img) file.close () effect is as follows

The first group of black-and-white old photos:

The second group of black and white old photos--

The third group of black and white old photos--

The above is all the contents of this article entitled "what are the tips for Python to repair and color old photos?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report