Eyes Tracking Mediapipe, part1
In this Video Series, we will how to estimate the position of Eyes, in this particticular post, we will detect the landmarks of different part, of face mesh of Mediapipe.
The following topics will be covered in this Tutorial.
- Detect Landmarks of face mesh.
- To draw landmarks, different parts like eyes, an oval face, eyebrows, and mouth.
- To draw transparent overlay using OpenCV
Installation
# Windows
pip install medidapipe
# Linux or Mac
pip3 install mediapipe
Landmarks detection
landmarks detection function which really simple which takes the normalized landmark, forms mediapipe, converts it image coordinate, each (x,y) point in the image, representing the pixel, corresponds to the image.
This function takes, three arguments
img (mat) which is nothing but image/frame(mat)
results(object) the landmarks returns by mediapipe
draw (boolean) if it's True then the circles will be drawn on each landmark.
This function returns a list of tuples contains image coordinates(x,y) of each landmark.
# landmark detection function
def landmarksDetection(img, results, draw=False):
img_height, img_width= img.shape[:2]
# list[(x,y), (x,y)....]
mesh_coord = [(int(point.x * img_width), int(point.y * img_height)) for point in results.multi_face_landmarks[0].landmark]
if draw :
[cv.circle(img, p, 2, utils.GREEN, -1) for p in mesh_coord]
# returning the list of tuples for each landmarks
return mesh_coord
Complete code
there are two files, one for landmarks detection other is a module that allows drawing transparent shapes, you have to put them into the same directory or clone the repository
This python file allows drawing transparent shapes and text with colour or blurred background
Comments
Post a Comment