[PYTHON] I tried'Beauty'with OpenCV

Long time no see. I posted about 9 months, thinking that it would be bad if I didn't post it soon. This time, I wrote the code of'Beauty'using OpenCV of python and tried it. Please try it and compare before and after the image'Beauty'.

code

import cv2

image = cv2.imread('photo.jpg')
value = 20
image_dst = cv2.bilateralFilter(image,value,value * 2,value / 2)
cv2.imwrite('new_photo.png',image_dst)
cv2.namedWindow('image')
cv2.imshow('image',image_dst)
cv2.waitKey(0)
cv2.destroyAllWindows()

Code description

Import OpenCV

import cv2

Load image

image = cv2.imread('photo.jpg')

The larger the beauty value value of the image, the stronger the beauty effect, and the smaller the beauty value value, the weaker the beauty effect.

value = 20
image_dst = cv2.bilateralFilter(image,value,value * 2,value / 2)

Save the new image to a file

cv2.imwrite('new_photo.png',image_dst)

Make a window

If you want to create a window in advance and display the image read later. Use cv2.namedWindow (window_name, flag)

cv2.namedWindow('image')

open window

cv2.imshow('image',image_dst)

Wait for window

Input wait time in milliseconds

cv2.waitKey(0)

close window

A function that closes all windows created so far. If you want to close only a specific window, specify the window name you want to close in the cv2.destroyWindow () function.

cv2.destroyAllWindows()

This is the end of this "I tried'Beauty'with OpenCV". Thank you very much for reading.

Recommended Posts

I tried'Beauty'with OpenCV
I examined OpenCV filtering
I tried trimming efficiently with OpenCV
I tried using GrabCut of OpenCV
I tried face recognition with OpenCV
OpenCV AI Kit (OAK-D) I tried @ windows10
I checked the options of copyMakeBorder of OpenCV
About Opencv ②
About Opencv ③
I tried non-photorealistic rendering with Python + opencv
About Opencv ①
I tried "smoothing" the image with Python + OpenCV
I got an error when saving with OpenCV
I tried "differentiating" the image with Python + OpenCV
I tried object detection using Python and OpenCV
I tried to detect motion quickly with OpenCV
I tried "binarizing" the image with Python + OpenCV
I tried using the image filter of OpenCV