0

我目前正在根据面部地标计算实际距离,例如,我有以下两个地标,我可以从中获取地标。

地标[6]: (0.36116672, 0.93204623, 0.0019629495)

地标[164]: (0.36148804, 0.99501055, -0.06169401)

我将如何根据上述信息计算实际尺寸?

任何帮助将不胜感激

4

1 回答 1

0

也许您可以从 mediapipe(python) face_mesh 文件中获得灵感。它在 mediapipe.solutions.drawing_utils 函数中,他们定义了一个名为

def _normalized_to_pixel_coordinates(
    normalized_x: float, normalized_y: float, image_width: int,
    image_height: int) -> Union[None, Tuple[int, int]]:
  """Converts normalized value pair to pixel coordinates."""

  # Checks if the float value is between 0 and 1.
  def is_valid_normalized_value(value: float) -> bool:
    return (value > 0 or math.isclose(0, value)) and (value < 1 or
                                                      math.isclose(1, value))

  if not (is_valid_normalized_value(normalized_x) and
          is_valid_normalized_value(normalized_y)):
    # TODO: Draw coordinates even if it's outside of the image bounds.
    return None
  x_px = min(math.floor(normalized_x * image_width), image_width - 1)
  y_px = min(math.floor(normalized_y * image_height), image_height - 1)
  return x_px, y_px 

它很容易理解。

于 2021-04-22T02:44:24.460 回答