mediapipe - 从用户脸上的两个地标计算大小
问题描述
我目前正在根据面部地标计算实际距离,例如,我有以下两个地标,我可以从中获取地标。
地标[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
它很容易理解。
推荐阅读
- c# - 如何为将字符串数组作为参数的 .Net Core 3.1 webapi 服务调用定义路由?
- sql-server - 如何运行会使其他查询运行更慢的 SQL Server 查询
- c++ - C++ 编译时特征值评估
- azure - 具有多个协变量特征的时间序列的 Azure AutoML 预测示例
- java - 自定义对话框 - 指定的孩子已经有一个父母
- javascript - 如何以角度获取具有相同名称但在不同界面中的数据
- postgresql - 取消或终止查询的日志是什么?
- python - 如何使用不均匀的子数组作为瓷砖来平铺一维 numpy 数组?
- sql - 删除重复记录,仅当记录差异小于 2 分钟时才保留最早
- reactjs - NextJS中没有状态的路由器事件和预加载器