Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

python learns to draw (above)


Jun 01, 2021 Article blog



This article was reproduced to Know ID: Charles (Bai Lu) knows his personal column

Download the W3Cschool Mobile App, 0 Foundation Anytime, Anywhere Learning Programming >> Poke this to learn

Lead

Originally wanted to use neural network to let the computer learn to draw pencil drawing and sketching, and later found that in fact do not use neural network effect can also, then the series from a simple start!

Let's put Tuha first!

 python learns to draw (above)1

Sand painting:

 python learns to draw (above)2  python learns to draw (above)3  python learns to draw (above)4  python learns to draw (above)5

Pencil drawing:

 python learns to draw (above)6  python learns to draw (above)7  python learns to draw (above)8  python learns to draw (above)9  python learns to draw (above)10  python learns to draw (above)11


File download

Baidu web download link: https://pan.baidu.com/s/1Y4ocZhhJuuRdWAJjWTh3MQ

Password: 26xi


Introduction to the principle

sketch:

sketch1.py:

Its main idea is that color pictures are first converted into grayscale pictures, and then simulate the process of drawing outlines and then gradually sketching details when people are painting.

Compare the difference between the pixel mean in a small area to the left of the pixel and the pixel mean in a small area on the right when contouring, and consider the point to be an outline point if the difference exceeds the preset range. se.

sketch2.py:

The principle is similar, but sketching in line units, and adding random functions, making the length of the line uncertain, and increasing to the upper and lower, left, top left, bottom right, top right, bottom left 8 adjudication blocks of comparison, so that the sketches created look softer, but also closer to the real human painting style.

Sand painting:

sand_paint.py:

In fact, the principle and pencil drawing is similar, the difference is to use random functions to simulate the blank background of sand grains, sand grain color depth, can be set by S_COLOR_LIGHT and S_COLOR_DARK.

 python learns to draw (above)12

OK, the code principle is introduced, in fact, very simple or very low. But it worked really well.

 python learns to draw (above)13  python learns to draw (above)14


How it works

Once python has set the environment variable, it can run in cmd. E nter the python file name and the original image path (including the image name) that you want features to be sketched or turned into sand. For example, the following image:

 python learns to draw (above)15

The picture is saved under the current path.


The next issue is announced

Let python imitate world famous paintings! That's an artificial intelligence topic that was hot before.

Like Van Gogh's Tiananmen and Shanghai:

 python learns to draw (above)16  python learns to draw (above)17