martes, 25 de agosto de 2020

# Project 1, part 2 feature apply Eye-Liners

 

Project 1, part 2 feature apply Eye-Liners

 

# Feature 2 Apply Eye-Liners or Eye-Lashes

 

I decided to draw the upper contour of the eye with a tail towars the ear. I can change the color of the eyeliner.

To get this goal, I create a contour outside the eye, later I fill up this contour with white and make a mask of three channels, I change the color of this mask with the color of the eyeliner, this array will be the foreground for the process of alpha blending.

I run the program in my system, testing several approaches:

 


The first part of this project is the same as in Project 1, part 1, apply lipstick:

.- First import libraries

.- import and setup the matplotlib with some parameters

.- mount the drive to access the files

.- load faceBlendCommon.py

.- Load landmark detector

.- Read Image

.- Calculate Landmarks

 

We read the image im from disk, we get a copy image2 from it, we can get the landmarks parts of the left eye and right eye

 

# Copy im in image2, the work image

# initialize mask4 to zero

 # make a list with the landmarks index of the right eye and another for the left eye.

# find the center of the coordinates of the left eye

 # find the center of the coordinates of the right eye

# list of values that dictate the extrapolate quantity of the upper points of the eyes

# create np arrays to save the points of the contour of the eye liners

# fill up the array linerLeft with the points near the left eye

# calculate and fill the array linerLeft up with the points far away from the left eye      

# create the empty list puntos8 and fill it up to keep the points that were in linerLeft

# plot the contour puntos8 with white color on the mask

# right eye 

# fill up the array linerRight with the points near the right eye

# calculate and fill the array linerRight up with the points far away from the right eye      

# create the empty list puntos9 and fill it up to keep the points that were in linerRight

# plot the contour puntos9 with white color on the mask

# create the foreground array

# assign color to eyeliner

# get alpha array with 3 channels from mask4

# copy im to background


# Convert uint8 to float

# Perform alpha blending

# Convert float to uint8

# change color space and show outImage as lipsRGB in plt


 

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: