laitimes

Crawl nearly a thousand beautiful photos of the goddess Hepburn, make a website and color the black and white photos in it, crawl the black and white photos to color the website

author:Salty

For Hepburn I believe that everyone is very familiar with, definitely a generation of goddesses, today we will climb the goddess of nearly a thousand beautiful photos, in a feast of the eyes at the same time, you can also learn how to do the website, for the old black and white photos, there is a key color function can play, it is really a lot of things

Crawl nearly a thousand beautiful photos of the goddess Hepburn, make a website and color the black and white photos in it, crawl the black and white photos to color the website

<h1 class="pgc-h-arrow-right" data-track="8" > photo crawling</h1>

The purpose website we chose is Time.com, without saying much, directly open the whole

Crawl nearly a thousand beautiful photos of the goddess Hepburn, make a website and color the black and white photos in it, crawl the black and white photos to color the website

http://people.mtime.com/951204/images

The website basically has no anti-crawler settings, and the web page structure is relatively simple, we directly code

Write a function that collects all the image URLs and a save function

Then you can parse the resulting files and crawl the pictures one by one

This requires us to complete the collection of the goddess's photo

Crawl nearly a thousand beautiful photos of the goddess Hepburn, make a website and color the black and white photos in it, crawl the black and white photos to color the website

We can see that a considerable part of the photos are black and white photos, which greatly affects our aesthetic experience, and the following coloring processing

<h1 class="pgc-h-arrow-right" data-track="19" > black and white</h1>

We chose to use the services provided by Baidu Cloud here, and there are about 300 free uses a year

Crawl nearly a thousand beautiful photos of the goddess Hepburn, make a website and color the black and white photos in it, crawl the black and white photos to color the website

To use the functions of Baidu Cloud, you need to log in first, and then create a project, specifically here will not be expanded, if there is a small partner here to encounter problems, you can add me WeChat private chat

Crawl nearly a thousand beautiful photos of the goddess Hepburn, make a website and color the black and white photos in it, crawl the black and white photos to color the website

After we create the application, we can see that there are two key values, which we need to use when calling the Baidu interface, namely API Key and Secret Key

Let's test the coloring function, let's choose a black and white photo

Crawl nearly a thousand beautiful photos of the goddess Hepburn, make a website and color the black and white photos in it, crawl the black and white photos to color the website

Well, it's time to lick the screen ()

Let's start coding and get the access token first

Next we construct the request message for the shaded interface

If nothing else, we can save the returned color picture

Let's look at the effect

Crawl nearly a thousand beautiful photos of the goddess Hepburn, make a website and color the black and white photos in it, crawl the black and white photos to color the website

It's still quite good, and I feel that the appearance of the goddess has also increased by a few points in an instant

The process of black and white photo coloring has run through, and we will start to make a website, through the buttons of the page to select the image has been colored request

<h1 class="pgc-h-arrow-right" data-track="34" > coloring website</h1>

Or use flask to build a web service

Next, let's look at the page layout in the index, the overall effect is as follows

Crawl nearly a thousand beautiful photos of the goddess Hepburn, make a website and color the black and white photos in it, crawl the black and white photos to color the website

The left side is used to select a black and white image, and when you click the "Paint Picture" button, the painted picture appears on the right

Let's take a look at some of the index file code, the main body is built using bootstrap

In the input component above, the function intro_pic is called, let's look at the code

This part of the code is used to handle the display of the image, that is, when we upload the image, it is echoed back to the page

Let's look at the add_colorize function

Here, the image data of the base64 type of the frontend is passed to the backend, and then the Baidu API interface is directly requested through the processing of the backend

That's the front-end code, let's look at the back-end code

The above code takes the colored image data from the front end and saves it locally

Finally, let's look at a final rendering

Crawl nearly a thousand beautiful photos of the goddess Hepburn, make a website and color the black and white photos in it, crawl the black and white photos to color the website

Let's take another GIF

Crawl nearly a thousand beautiful photos of the goddess Hepburn, make a website and color the black and white photos in it, crawl the black and white photos to color the website

Looks good, oh, let's practice it together!

Read on