Implement simple face mask, glasses, beard, nose special effects based on OpenCV (detailed steps + source code)

Click the card below to follow the public account of " OpenCV and AI Deep Learning "!

Visual/image heavy dry goods, delivered as soon as possible!

Guided reading

This article will share with you an example of a simple face mask, glasses, beard, and nose special effects based on OpenCV, along with the implementation steps and source code. (Public Number: OpenCV and AI Deep Learning)

Background introduction

    OpenCV traditional face detection is implemented using cascaded classifiers of Haar features. Harr cascade is a cascade classifier based on Haar features. What is Cascade Classifier? It is a process of concatenating weak classifiers into strong classifiers. What are weak classifiers and strong classifiers? Weak classifiers are performance-limited classifiers that do not correctly distinguish everything. If your problem is simple, its output will be in an acceptable range. A strong classifier can correctly classify the data. The image below shows how they fit together. Another important part of the Haar cascade is the Haar features, which simply summarize the difference between different rectangular regions, as shown in the following figure:

    To calculate the Haar feature of the ABCD area, you only need to calculate the difference between white pixels and colored pixels in this area. Different patterns were used to create the Haar feature in the four diagrams above, and other patterns were also used. These patterns use a multi-scale approach to ensure that the stretching of the system is invariant. The multi-scale method refers to reducing the image and calculating the same features again. This gives a reliable result given object size differences.

    The OpenCV installation directory provides a number of trained Haar classifier model files, including: face detection, eye detection, nose detection, and body detection, as shown in the following figure:

Guess you like

Origin blog.csdn.net/stq054188/article/details/123358489