Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does python paint?

Shulou Source: shulou.com Published: 2022-05-31 10:50:29 10月03日 Update

This article introduces the relevant knowledge of "how to paint in python". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Pip install python-opencv

However, it also has limitations, we can only use models trained by others for style transfer, if we want to customize the style, we must configure tools such as cudn and use the methods of projects such as deep-photo-styletransfer for training. In today's tutorial, we use the model trained by fast-neural-style to do a style transfer to the following picture.

1. Selection model

There are 9 model styles released by fast-neural-style. We will try them one by one. Some of them are as follows:

Candy

Mosaic

Starry_night

two。 Clone OpenCV source code

Code:

Note that the source code is based on Python2, so line 46 is missing parentheses, if you are Python3, please pay attention to the parentheses. This code can be used directly, parser defines five parameters,-input input to migrate the image width and height, median_filter is the median filter, the basic idea is to use the pixel neighborhood gray value of the median value to replace the pixel gray value, so the larger the theoretical value, the smoother the image, the better the details of the output results (uncertain). I personally tried the impact of median_filter on the image and found that the change was minimal, so it was fine with the default value.

3. Start the migration

Save the code in step 2 to a file named 1.py, and run the script with parameters in CMD/Terminal, where input is the source image path and model is the migrated style model file, such as running:

$python 1.py-input 1.jpg-model udnie.t7

Effect:

Migration effects of all 9 styles:

This is the end of the content of "how to draw python". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Style model code image training painting median pixels content parameters parentheses effects files more grayscale knowledge output run smooth minimal Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB NVidia Microsoft Redmi