问题描述
我目前正在根据人脸地标计算实际距离,例如,我有以下两个地标,我可以为其输出地标。
地标[6]:(0.36116672,0.93204623,0.0019629495)
地标[164]:(0.36148804,0.99501055,-0.06169401)
如何根据以上信息计算实际尺寸?
任何帮助将不胜感激
解决方法
也许你可以从 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
很容易理解。