This can be achieve via mp.solutions.face_mesh.FaceMesh
First get the face bb
results = face_mesh.process(cv2.cvtColor(image_input , cv2.COLOR_BGR2RGB))
Then for each eye region of interest, get the pixel position using the _normalized_to_pixel_coordinates
eye_r = _normalized_to_pixel_coordinates()
The full code is as below
import cv2
import mediapipe as mp
from mediapipe.python.solutions.drawing_utils import _normalized_to_pixel_coordinates
dframe = cv2.imread("detect_face/person.png")
image_input = cv2.cvtColor(dframe, cv2.COLOR_BGR2RGB)
face_mesh = mp.solutions.face_mesh.FaceMesh(static_image_mode=True, max_num_faces=2,
min_detection_confidence=0.5)
image_rows, image_cols, _ = dframe.shape
results = face_mesh.process(cv2.cvtColor(image_input , cv2.COLOR_BGR2RGB))
fl=results.multi_face_landmarks[0]
##
for txt,cor in zip(['L','R','T','B'],[263, 362,386,374]):
eye_r = _normalized_to_pixel_coordinates(fl.landmark[cor].x,fl.landmark[cor].y,
image_cols,image_rows)
cv2.putText(image_input, txt, eye_r,cv2.FONT_HERSHEY_SIMPLEX, 0.3, (0, 0, 255), 2)
for txt,cor in zip(['l','r','t','b'],[133,33,159,145]):
eye_r = _normalized_to_pixel_coordinates(fl.landmark[cor].x,fl.landmark[cor].y,
image_cols,image_rows)
cv2.putText(image_input, txt, eye_r,cv2.FONT_HERSHEY_SIMPLEX, 0.3, (0, 0, 255), 2)
cv2.imwrite('test.png', image_input)
Which output