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
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!
Sand painting:
Pencil drawing:
Baidu web download link:
https://pan.baidu.com/s/1Y4ocZhhJuuRdWAJjWTh3MQ
Password: 26xi
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.
OK, the code principle is introduced, in fact, very simple or very low. But it worked really well.
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:
The picture is saved under the current path.
Let python imitate world famous paintings! That's an artificial intelligence topic that was hot before.
Like Van Gogh's Tiananmen and Shanghai: