102102 "outputs" : [],
103103 "source" : [
104104 " #@markdown We implemented some functions to visualize the face landmark detection results. <br/> Run the following cell to activate the functions.\n " ,
105- " \n " ,
106- " from mediapipe import solutions\n " ,
107- " from mediapipe.framework.formats import landmark_pb2\n " ,
105+ " import mediapipe as mp\n " ,
106+ " from mediapipe.tasks import python\n " ,
107+ " from mediapipe.tasks.python import vision\n " ,
108+ " from mediapipe.tasks.python.vision import drawing_utils\n " ,
109+ " from mediapipe.tasks.python.vision import drawing_styles\n " ,
108110 " import numpy as np\n " ,
109111 " import matplotlib.pyplot as plt\n " ,
110112 " \n " ,
118120 " face_landmarks = face_landmarks_list[idx]\n " ,
119121 " \n " ,
120122 " # Draw the face landmarks.\n " ,
121- " face_landmarks_proto = landmark_pb2.NormalizedLandmarkList()\n " ,
122- " face_landmarks_proto.landmark.extend([\n " ,
123- " landmark_pb2.NormalizedLandmark(x=landmark.x, y=landmark.y, z=landmark.z) for landmark in face_landmarks\n " ,
124- " ])\n " ,
125123 " \n " ,
126- " solutions.drawing_utils.draw_landmarks(\n " ,
124+ " \n " ,
125+ " drawing_utils.draw_landmarks(\n " ,
127126 " image=annotated_image,\n " ,
128- " landmark_list=face_landmarks_proto ,\n " ,
129- " connections=mp.solutions.face_mesh.FACEMESH_TESSELATION ,\n " ,
127+ " landmark_list=face_landmarks ,\n " ,
128+ " connections=vision.FaceLandmarksConnections.FACE_LANDMARKS_TESSELATION ,\n " ,
130129 " landmark_drawing_spec=None,\n " ,
131- " connection_drawing_spec=mp.solutions.drawing_styles\n " ,
132- " .get_default_face_mesh_tesselation_style())\n " ,
133- " solutions.drawing_utils.draw_landmarks(\n " ,
130+ " connection_drawing_spec=drawing_styles.get_default_face_mesh_tesselation_style())\n " ,
131+ " drawing_utils.draw_landmarks(\n " ,
134132 " image=annotated_image,\n " ,
135- " landmark_list=face_landmarks_proto ,\n " ,
136- " connections=mp.solutions.face_mesh.FACEMESH_CONTOURS ,\n " ,
133+ " landmark_list=face_landmarks ,\n " ,
134+ " connections=vision.FaceLandmarksConnections.FACE_LANDMARKS_CONTOURS ,\n " ,
137135 " landmark_drawing_spec=None,\n " ,
138- " connection_drawing_spec=mp.solutions.drawing_styles\n " ,
139- " .get_default_face_mesh_contours_style())\n " ,
140- " solutions.drawing_utils.draw_landmarks(\n " ,
136+ " connection_drawing_spec=drawing_styles.get_default_face_mesh_contours_style())\n " ,
137+ " drawing_utils.draw_landmarks(\n " ,
138+ " image=annotated_image,\n " ,
139+ " landmark_list=face_landmarks,\n " ,
140+ " connections=vision.FaceLandmarksConnections.FACE_LANDMARKS_LEFT_IRIS,\n " ,
141+ " landmark_drawing_spec=None,\n " ,
142+ " connection_drawing_spec=drawing_styles.get_default_face_mesh_iris_connections_style())\n " ,
143+ " drawing_utils.draw_landmarks(\n " ,
141144 " image=annotated_image,\n " ,
142- " landmark_list=face_landmarks_proto ,\n " ,
143- " connections=mp.solutions.face_mesh.FACEMESH_IRISES ,\n " ,
145+ " landmark_list=face_landmarks ,\n " ,
146+ " connections=vision.FaceLandmarksConnections.FACE_LANDMARKS_RIGHT_IRIS ,\n " ,
144147 " landmark_drawing_spec=None,\n " ,
145- " connection_drawing_spec=mp.solutions.drawing_styles\n " ,
146- " .get_default_face_mesh_iris_connections_style())\n " ,
148+ " connection_drawing_spec=drawing_styles.get_default_face_mesh_iris_connections_style())\n " ,
147149 " \n " ,
148150 " return annotated_image\n " ,
149151 " \n " ,
337339 },
338340 "nbformat" : 4 ,
339341 "nbformat_minor" : 0
340- }
342+ }
0 commit comments