Today I’m going to share with you a very fun and interesting Python applet. Many people like to take cartoon characters as their profile pictures, and little sister also wants to show her own profile pictures with personality. Wouldn’t it be interesting if I could have a program that could easily turn my head into oil paintings, cartoons and sketches? Today I will share it with you. Let’s have a look. Different people also like different styles of profile pictures.

Comic style: comic style has a lively and lovely, youthful elements, can gallop freely between the vast world, giving people the feeling of freedom is always close to.

Oil painting style: oil painting is more suitable for grand epic works with stereoscopic painting style. Accordingly, the feeling that oil painting gives a person is elegant, temperament is elegant, make a person appreciate.

Sketch style: a pencil, through the outline of black and white lines, to depict a vivid character image. Sketch gives a person is a simple wind, intoxicating

01. Program idea

In daily life, we often like to express our feelings and mood by changing our avatar. When we are happy, when we are sad, our wechat avatar can become the pronoun of our mood at every moment.

Although we can’t ask art masters to help us draw different styles of wechat profile pictures in real time, we can do it through the program. No more talking, we can get started.

1). Comic style

Turning a photo into a comic book style requires sharpness and color richness.

The program first reduces the clarity of the image by the bilateralFilter function in opencv, and then finds the boundary of the gray image by the adaptiveThreshold function adaptiveThreshold to highlight the contour information of the boundary. Finally, the gray image is converted into color image to complete the cartoon style switch.

2) oil painting style

Oil painting style pictures can use oil color to give life to the characters in the oil painting. We often see many realistic oil paintings on the Internet. The high fidelity makes people unable to see whether it is oil painting or a living person.

Van Gogh once said, I dream of painting, I paint my dream.

Oil painting gives a person with sense of reality, the key lies in the grasp of color and use. Part of the process of picture to oil painting style is shown below.

The program calculates the pixel mean of the original image by obtaining the largest number of pixels in the gray image and its index, and writes the pixel mean into the oil painting to complete the oil painting style transformation of the image.

3). Sketch style

When converting a picture into a sketch format, the most important thing is to highlight the boundary information, such as the outline of the face, the outline of the facial features. Part of the program is shown below.

In the program, imG2 used 10 times of filter processing, the more times of filter processing, for the final sketch picture, the stronger the shadow effect. Replace pixel values according to their size by iterating through the pixel values of each element in IMG1.

2. Video presentation Through video presentation, we will look at how to execute the program and get the final result. 3. Conclusion The above program is actually mainly used the famous OpencV library, it is very powerful in image and visual processing, Python in many fields have awesome wheels, you can easily use, build you want to complete the program, interested partners, you can find newbie brother source program.

How to obtain the source code:

① More than 3000 Python ebooks ②Python development environment installation tutorial ③Python400 set self-learning video ④ software development common vocabulary ⑤Python learning roadmap ⑤ project source code case sharing if you use it can be directly taken away in my QQ technical exchange group group number: 739021630 (technical exchange and resource sharing only, no advertising allowed) for self help

Click here to collect