Extracting 3D Face Mesh Points with MediaPipe in Python
This article demonstrates how to use MediaPipe's Python API to extract 468 3D facial landmark points, configure detection parameters, and visualize the results with OpenCV, providing code examples and references to related research papers.
Reading font

This article introduces a method for extracting 3D facial point cloud data using MediaPipe, yielding 468 facial landmarks whose coordinates range from 0 to 1, with the z‑axis representing depth.
Relevant research papers can be found at https://arxiv.org/pdf/1907.06724.pdf and https://arxiv.org/pdf/2006.10962.pdf.
The overall workflow is illustrated by three diagrams:
The extracted 468 points are 3D coordinates with values between 0 and 1; the z value indicates depth. The Python function supports the following parameters: max_num_faces (default 1) – maximum number of faces to detect. min_detection_confidence (default 0.5) – minimum detection confidence. min_tracking_confidence (default 0.5) – minimum tracking confidence.
Below is a modified Python script based on the official MediaPipe tutorial that captures video, processes each frame, and draws the face mesh:
import cv2
import mediapipe as mp
mp_drawing = mp.solutions.drawing_utils
mp_face_mesh = mp.solutions.face_mesh
drawing_spec = mp_drawing.DrawingSpec(thickness=1, circle_radius=1)
cap = cv2.VideoCapture("D:/images/video/face_mesh.mp4")
with mp_face_mesh.FaceMesh(
max_num_faces=4,
min_detection_confidence=0.5,
min_tracking_confidence=0.5) as face_mesh:
while cap.isOpened():
success, frame = cap.read()
if not success:
print("Ignoring empty camera frame.")
break
h, w, c = frame.shape
image = cv2.resize(frame, (w // 2, h // 2))
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results = face_mesh.process(image)
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
if results.multi_face_landmarks:
for face_landmarks in results.multi_face_landmarks:
mp_drawing.draw_landmarks(image=image, landmark_list=face_landmarks)
cv2.imshow('MediaPipe Face Mesh', image)
if cv2.waitKey(5) & 0xFF == 27:
break
cap.release()The execution result is shown in the following image:
*Disclaimer: This article is compiled from online sources; copyright belongs to the original authors. Please contact us for removal or licensing if any rights are infringed.
For questions about attribution, corrections or content rights, please contactand we will review it promptly.