MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / get_face_bboxes

Function get_face_bboxes

tools/preprocess/utils.py:168–193  ·  view source on GitHub ↗
(kp2ds, scale, image_shape)

Source from the content-addressed store, hash-verified

166
167
168def get_face_bboxes(kp2ds, scale, image_shape):
169 h, w = image_shape
170 kp2ds_face = kp2ds.copy()[1:] * (w, h)
171
172 min_x, min_y = np.min(kp2ds_face, axis=0)
173 max_x, max_y = np.max(kp2ds_face, axis=0)
174
175 initial_width = max_x - min_x
176 initial_height = max_y - min_y
177
178 initial_area = initial_width * initial_height
179
180 expanded_area = initial_area * scale
181
182 new_width = np.sqrt(expanded_area * (initial_width / initial_height))
183 new_height = np.sqrt(expanded_area * (initial_height / initial_width))
184
185 delta_width = (new_width - initial_width) / 2
186 delta_height = (new_height - initial_height) / 4
187
188 expanded_min_x = max(min_x - delta_width, 0)
189 expanded_max_x = min(max_x + delta_width, w)
190 expanded_min_y = max(min_y - 3 * delta_height, 0)
191 expanded_max_y = min(max_y + delta_height, h)
192
193 return [int(expanded_min_x), int(expanded_max_x), int(expanded_min_y), int(expanded_max_y)]

Callers 1

_build_face_imagesMethod · 0.90

Calls 1

copyMethod · 0.80

Tested by

no test coverage detected