Git Product home page Git Product logo

virtual-makeup-iris-eyes's Introduction

Virtual Makeup

Virtual Makeup

With a virtual makeup try-on tool implemented in this project you can:

  • Apply lipstick

  • Change eye color

More features will be added in time.

The usage details are described below.

Set Up

It is assumed that OpenCV 4.x, C++17 compiler, and cmake 3.0 or newer are installed on the system.

Project structure

The project has the following directory structure:

│   .gitignore
│   README.md
│   
├───assets
│       
├───dlib
│               
├───images
│       
├───models
│       shape_predictor_68_face_landmarks.dat
│       
├───src
│   │   abstractboxdetector.h
│   │   abstractimagefilter.cpp
│   │   abstractimagefilter.h
│   │   abstractlandmarkdetector.h
│   │   CMakeLists.txt
│   │   eyecolorfilter.cpp
│   │   eyecolorfilter.h
│   │   faciallandmarkdetector.cpp
│   │   faciallandmarkdetector.h
│   │   faciallandmarkfilter.cpp
│   │   faciallandmarkfilter.h
│   │   lipstickcolorfilter.cpp
│   │   lipstickcolorfilter.h
│   │   main.cpp
│   │   
│   └───build
│                           
└───writeup
        eye_color.docx
        lipstick.docx
        

Download Dlib

Dlib C++ library can be downloaded from dlib.net. The project was tested with Dlib 19.21.

After downloading extract the archive to the dlib folder in the project root (see the directory structure above).

Download the Facial Landmark Detection Model

Download the 68 facial landmark predictor from here. Just in case the URL doesn't work, consult this page.

Extract the predictor to the models folder in the project root (see the directory structure above).

Specify OpenCV_DIR in CMakeLists

Open CMakeLists.txt and set the correct OpenCV directory in the following line:

set(OpenCV_DIR /opt/opencv/4.5.1/installation/lib/cmake/opencv4)

Depending on the platform and the way OpenCV was installed, it may be needed to provide the path to cmake files explicitly. On my KUbuntu 20.04 after building OpenCV 4.5.1 from sources the working OpenCV_DIR looks like /lib/cmake/opencv4. On Windows 8.1 after installing a binary distribution of OpenCV 4.2.0 it is C:\OpenCV\build.

Build the Project

In the src folder create the build directory unless it already exists. Then from the terminal run the following:

cd build
cmake ..

This should generate the build files. When it's done, compile the code:

cmake --build . --config Release

Usage

The program has to be run from the command line. It takes in the path to the image file and several optional parameters:

vimaku  --input=<input image file>
	[--output=<output image file>]
	[--lipstick_color=<The new lipstick color>]
	[--eye_color=<The new eye color>]		
	[--help]
Parameter Meaning
help, ? Prints the help message.
input The input image file.
output If not empty, specifies the output file where the output image will be saved to.
lipstick_color The new lipstick color in RRGGBBAA notation. If empty, the lipstick filter will not be applied.
eye_color The new iris color in RRGGBBAA notation. If empty, the eye color filter will not be applied.

The RRGGBBAA color notation is similar to the one used in CSS, but you don't need to prepend it with the hash sign. The first 6 digits define the values of R, G, B components. The last pair of digits, interpreted as a hexadecimal number, specifies the alpha channel of the color, where 00 represents a fully transparent color and FF represents a fully opaque color. In case the alpha component is omitted, it is assumed to be FF. For example, FF000070 specifies a pure semi-transparent red color. FF0000 and ff0000ff are identical and specify a fully opaque red color.

Applying lipstick example:

./vimaku --input=./images/girl-no-makeup.jpg --lipstick_color=FF000050 

This will add a mild red lipstick effect:

Applying lipstick

For realistic look I recommend alpha values from 30 to 70.

Changing eye color example:

./vimaku --input=./images/girl7.png --eye_color=2E1902CC  

This will change the iris color to brown: Brown eyes

Recommended values of alpha for the eye color filter depend on the original iris color and the intensity of the new color. When eyes are originally light, the alpha values should normally be less than 70.

Filters can be applied together:

./vimaku --input=./images/girl5_small.jpg --eye_color=4b724882 --lipstick_color=ff7f5050 --ouput=out.jpg  

This will change the iris color to blue and the lipstick color to orange. The output image will be saved to out.jpg.

Blue eyes and orange lipstick

Credits

Images have been downloaded from pinterest.com.

virtual-makeup-iris-eyes's People

Contributors

puhach avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.