0

I am currently working on calculating actual distance based on face landmark, for example I have the following two landmarks for which I can get the landmark out put.

Landmark[6]: (0.36116672, 0.93204623, 0.0019629495)

Landmark[164]: (0.36148804, 0.99501055, -0.06169401)

How would I calculate the actual size based on the above information?

Any help would be greatly appreciated

dogwasstar
  • 852
  • 3
  • 16
  • 31

1 Answers1

0

Maybe you can take inspiration from mediapipe(python) face_mesh file . it's in mediapipe.solutions.drawing_utils function, they defined a function called

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 

its easy to understand.

aoxipo
  • 1