Welcome to MicroROS V2 Robot Car repository
4. Facial Detection
Face Detection
1. Experiment Objective
Use MediaPipe Face Mesh to detect facial landmarks in the camera image, generating 468 facial mesh points and drawing contour connections.
2. Experiment Principle
1. Key Terms
| Keyword | Description |
|---|---|
| MediaPipe Face Mesh | Google's facial mesh detection model, which outputs 468 3D facial landmarks covering the contours of facial features and the surface of the face |
| Face Mesh | A 468-point topology connected by triangular faces (Tessellation), finer than simple keypoints |
| Facial contours | Contour lines drawn from a specific subset of the 468 point indices (eyebrows, eyes, lips, outer face contour) |
2. Technical Architecture
Terminal 1: start agent + camera + joint modelsTerminal 2: start face detection
3. Experiment Steps
1. Hardware Preparation
| Hardware | Requirement |
|---|---|
| PTZ version | ✅ Supported |
| No-PTZ version | ✅ Supported |
| Required peripherals | ESP32 camera |
2. Start the agent + camera + joint models (Terminal 1)
xxxxxxxxxxros2 launch microros_v2_bringup car_base.launch.py
3. Start face detection (Terminal 2)
xxxxxxxxxxros2 launch microros_v2_mediapipe_pkg face_mesh.launch.py4. Operating Instructions
Press q to exit.
4. Observed Results
- The face is covered by 468 white dots, with triangular faces forming a fine facial surface mesh
- Facial contour lines (eyebrows, eyes, lips, outer face contour) are annotated in distinctive colors

5. Code Walkthrough
Source code paths:
- Launch:
~/microros_ws/src/microros_v2_mediapipe_pkg/launch/face_mesh.launch.py- Node:
~/microros_ws/src/microros_v2_mediapipe_pkg/microros_v2_mediapipe_pkg/FaceMesh.py
1. Core Node Analysis
x# Source file: ~/microros_ws/src/microros_v2_mediapipe_pkg/microros_v2_mediapipe_pkg/FaceMesh.pyclass FaceMesh(Node): def __init__(self): super().__init__("face_mesh_node") self.mp_face_mesh = mp.solutions.face_mesh self.face_mesh = self.mp_face_mesh.FaceMesh( static_image_mode=False, max_num_faces=1, min_detection_confidence=0.5, min_tracking_confidence=0.5) def image_callback(self, msg): frame = self.bridge.imgmsg_to_cv2(msg, 'bgr8') results = self.face_mesh.process(cv.cvtColor(frame, cv.COLOR_BGR2RGB)) if results.multi_face_landmarks: for face_landmarks in results.multi_face_landmarks: self.mp_draw.draw_landmarks( frame, face_landmarks, self.mp_face_mesh.FACEMESH_TESSELATION, ...) cv.imshow(self.window_name, frame)Key logic:
mp.solutions.face_mesh.FaceMesh(): 468-point facial mesh detectormax_num_faces=1: detects 1 face by default; increase it to support multiple facesFACEMESH_TESSELATION: triangular face topology that represents the facial surface more finely than skeleton connections- Supports
FACEMESH_CONTOURS(contour mode), which only draws facial contour lines (eyebrows, eyes, lips, outer contour) to reduce visual complexity
2. Key Parameters
Parameter definition files:
- Launch:
~/microros_ws/src/microros_v2_mediapipe_pkg/launch/face_mesh.launch.py- Node:
~/microros_ws/src/microros_v2_mediapipe_pkg/microros_v2_mediapipe_pkg/FaceMesh.py
| Parameter | Type | Default | Description |
|---|---|---|---|
max_num_faces | int | 1 | Maximum number of faces to detect |
static_image_mode | bool | false | Whether to detect each frame independently |
min_detection_confidence | float | 0.5 | Detection confidence threshold |
min_tracking_confidence | float | 0.5 | Tracking confidence threshold |
3. Node Description
| Node | Function |
|---|---|
face_mesh_node | MediaPipe Face Mesh 468-point facial mesh detection + visualization |
6. Frequently Asked Questions
| Issue | Cause | Solution |
|---|---|---|
| Face not detected | Profile angle is too large | Face the camera directly |
| Frame lag / stutter | 468-point mesh rendering is expensive | Switch to contour mode to reduce rendering complexity |