Revive Your 18‑Year‑Old Look with a 30‑Line Python OpenCV Beauty Filter

On the cusp of the 2017 year‑end, the author humorously marks the last 90‑post turning 18 while offering a Python‑OpenCV tutorial that, in just 30 lines of code, applies a beauty filter to make anyone look younger, complete with installation steps and sample output.

AI Cyberspace
AI Cyberspace
AI Cyberspace
Revive Your 18‑Year‑Old Look with a 30‑Line Python OpenCV Beauty Filter

Today you might be seeing a flood of “18‑year‑old” posts because, on December 31 2017, the last of the 1999‑born “90‑post” generation will turn 18, marking the legal adulthood of the entire 90‑post cohort and the rise of the “00‑post” generation.

As a middle‑aged tech enthusiast, I’m joining the celebration by sharing a nostalgic photo‑revival trick: with just 30 lines of Python you can make yourself look 18 again.

OpenCV

OpenCV (Open Source Computer Vision Library) was founded by Intel in 1999 and is now supported by Willow Garage. It is a cross‑platform, BSD‑licensed library that provides a wide range of computer‑vision algorithms, with interfaces for C, C++, Python, Ruby, MATLAB and more.

The library is lightweight and efficient, consisting of many C functions and a few C++ classes, and it is widely used in artificial‑intelligence applications such as image recognition, motion tracking, and machine vision.

Installing the Python + OpenCV environment

pip install --upgrade setuptools
pip install numpy Matplotlib
pip install opencv-python

Applying OpenCV to create a beauty filter

# -*- coding: utf-8 -*-
'''
Skin‑smoothing algorithm
Dest =(Src * (100 - Opacity) + (Src + 2 * GuassBlur(EPFFilter(Src) - Src + 128) - 256) * Opacity) /100 ;
'''
import cv2
import numpy as np

def beauty_face(img):
    dst = np.zeros_like(img)
    # v1, v2 control smoothing and detail levels
    v1 = 3
    v2 = 1
    # bilateral filter parameters
    dx = v1 * 5
    fc = v1 * 12.5
    # opacity
    p = 0.1
    temp4 = np.zeros_like(img)
    # bilateral filter
    temp1 = cv2.bilateralFilter(img, dx, fc, fc)
    temp2 = cv2.subtract(temp1, img)
    temp2 = cv2.add(temp2, (10,10,10,128))
    # Gaussian blur
    temp3 = cv2.GaussianBlur(temp2, (2*v2-1, 2*v2-1), 0)
    temp4 = cv2.add(img, temp3)
    dst = cv2.addWeighted(img, p, temp4, 1-p, 0.0)
    dst = cv2.add(dst, (10,10,10,255))
    return dst

# load source photo
img = cv2.imread('./fanguiju.jpeg')
dst = beauty_face(img)
cv2.imshow("SRC", img)
cv2.imshow("DST", dst)
cv2.waitKey()
cv2.destroyAllWindows()

Result

Before and after image
Before and after image

Instantly the middle‑aged uncle turns into a handsome young man—give it a try!

Conclusion

This is likely the last post of 2017. Thank you all for your support this year; I look forward to staying in touch and wish everyone a happy new year and good health. See you next year!

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Computer VisionPythonImage ProcessingOpenCVBeauty Filter
AI Cyberspace
Written by

AI Cyberspace

AI, big data, cloud computing, and networking.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.