Virtual Makeup: Eyeliner Effect using OpenCV and Dlib
In this post we will learn how to apply eyeliner color using OpenCV and Dlib.
In this post we will walk through the solution to apply eyeliner
We are using dlib to detect the face and extract facial landmark. We will use OpenCV capabilities to do image processing.
These are the steps needed
- Image with face
- Detect face on the image
- Find both eyes landmark using dlib.
- Apply eye liner on eyes
- Display image with applied eyeliner
Step 1 and 3 we have discussed in our previous post Apply Lipstick Effect
Step 3: Find both eyes landmark using dlib
consider points array contains all the landmarks
Left eye represented by indcies 36 to 42 in points
Right eye represented by indcies 42 to 48 in points
left_eye = np.array(points[36:42])
right_eye = np.array(points[42:48])
Step 4: Apply eyeliner on eyes
To apply eyeliner on eyes we will use cv2.polylines()
this method accept color of the eyeliner and thickness of the eyeliner and the points (i.e eye contours)
color = (0,0,0) # Eyeliner color
thickness = 3 # Eyeliner thickness
cv2.polylines(im_eyeliner,[left_eye], True, color=color, thickness = thickness)
cv2.polylines(im_eyeliner,[right_eye], True, color=color, thickness = thickness)
Step 5: Display image with applied eyeliner
In step 4 we have drawn the polylines on im_eyeliner
on each eyes
plt.imshow(im_eyeliner)
as we have seen with simple image processing we can get this Eyeliner effect on any face.
This is the complete code
# Apply Eyeliner
im_eyeliner = imDlib.copy()
left_eye = np.array(points[36:42])
right_eye = np.array(points[42:48])
color = (0,0,0) # Eyeliner color
thickness = 3 # Eyeliner thickness
cv2.polylines(im_eyeliner,[left_eye], True, color=color, thickness = thickness)
cv2.polylines(im_eyeliner,[right_eye], True, color=color, thickness = thickness)
plt.imshow(im_eyeliner)
References: