MCPcopy Create free account
hub / github.com/antgroup/echomimic / draw_points

Method draw_points

src/utils/draw_utils.py:132–156  ·  view source on GitHub ↗

We have a custom function to draw the pupils because the mp.draw_landmarks method requires a parameter for all landmarks. Until our PR is merged into mediapipe, we need this separate method.

(self, image, landmark_list, drawing_spec, halfwidth: int = 2)

Source from the content-addressed store, hash-verified

130 self.draw_nose = draw_nose
131
132 def draw_points(self, image, landmark_list, drawing_spec, halfwidth: int = 2):
133 """We have a custom function to draw the pupils because the mp.draw_landmarks method requires a parameter for all
134 landmarks. Until our PR is merged into mediapipe, we need this separate method."""
135 if len(image.shape) != 3:
136 raise ValueError("Input image must be H,W,C.")
137 image_rows, image_cols, image_channels = image.shape
138 if image_channels != 3: # BGR channels
139 raise ValueError('Input image must contain three channel bgr data.')
140 for idx, landmark in enumerate(landmark_list.landmark):
141 if idx not in drawing_spec:
142 continue
143
144 if (
145 (landmark.HasField('visibility') and landmark.visibility < 0.9) or
146 (landmark.HasField('presence') and landmark.presence < 0.5)
147 ):
148 continue
149 if landmark.x >= 1.0 or landmark.x < 0 or landmark.y >= 1.0 or landmark.y < 0:
150 continue
151
152 image_x = int(image_cols * landmark.x)
153 image_y = int(image_rows * landmark.y)
154
155 draw_color = drawing_spec[idx].color
156 image[image_y - halfwidth : image_y + halfwidth, image_x - halfwidth : image_x + halfwidth, :] = draw_color
157
158
159 def draw_landmarks(self, image_size, keypoints, normed=False):

Callers 1

draw_landmarksMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected