martes, 25 de agosto de 2020

Project 1 Virtual Make-up Part 1 - Feature apply lipstick

 Project 1 Virtual Make-up Part 1 - Feature apply lipstick

Here we are again with another project:
Project1: Virtual Makeup
We have already seen interesting applications of facial features and landmarks such as aging, beardify, face swap etc.
 
In this project, you will build features for a Virtual Makeup application! Given below are a few features
that are required to be built in the application.
 
Apply Lipstick
Apply Blush
Apply Eye-Liners or Eye-Lashes
Apply Glasses
Apply Eye Color ( Lens Color)
Apply Hat/Cap
Apply Ear-Rings
Change Hair Color
Your Task
Implement any 2 features from the list above
 
The course staff has provided a sample image. You can use your own image for experimentation as well as come up with other interesting features. This is the image:

 
 
This is part 1, and the choosen feature is Apply Lipstick.
 
There are several ways of do it:
We read the image im from disk, we get a copy img2 from it, we can get the landmarks parts of the upper lip and use the function cv2.fillPoly() with the flag fill inside on the image img2, after that  we can get the landmarks parts of the lower lip and use the function cv2.fillPoly() with the flag fill inside on the image img2. we will get a solid color like this on the lips.


 
We can use the function image_new =addWeigthed(im, alpha, img2, (1-alpha),0), Then the lips get transparent as a funcion of alpha, and we get the shadows and lights that we wanted.

 
I was searching information about virtual makeup for this project, then I got this page:
https://rsrivatsan.wordpress.com/2016/03/05/virtual-makeup/  He wrote that you can get the mean in the zone of the lips in the color space Lab, then you add the difference between the mean and the color that you want, this way you preserve the texture. So I decided to try it for this part of the project.

Always try to run the program in my system:


Cell 7. - First import libraries

Cell 25.- import and setup the matplotlib with some parameters

Cell 28.- mount the drive to access the files
Cell 19.- load faceBlendCommon.py

Load landmark detector

We have provided code for loading the model for landmark detector.

Read Image

We load the image and convert it to RGB format so that it can be used by Dlib and also for displaying using matplotlib.

You can also use any other image.

Cell 22.- 
Calculate Landmarks
We are providing code for calculating the landmarks in this section. 
So that you can focus on the feature implementation.

# Copy im in image1, the work image 
# make a list with the landmarks index of the upper lip and another for the lower lip.
 
# Create the empty list puntos1 and puntos2 where will be saved the coordinates of the upper lip and lower lip landmarks.

# convert and reshape the lists puntos1 and puntos2 to np.array

    

 
# fill the array mascara filled with zeros, with a white mask of the upper and lower lip


 
# convert image1 to the color space Lab and get only the pixels of the mascara, get the mean of 
those pixels and the area inside contours puntos1 and puntos2







# Assign a color in the color space BGR and convert it to the color space Lab
 

# find the differences between the goal color and the mean in each chanel L. a, b. 







# We are going to do the substitution in each lips pixel, this could take long, so I will use a roi.



 
# For loop to do the substitution



 # convert from color space Lab to BGR



 
# convert from color space BGR to RGB compatible with plt.


  
# show the final image
The final image run in Google colab:


No hay comentarios:

Publicar un comentario