使用二维估计方法和多视图渲染进行3D关键点检测的简单方法。
项目描述
多视图3D关键点检测(Muke) 
基于blender项目,使用二维估计方法和多视图渲染进行3D关键点检测的简单方法,适用于自动关键点重新拓扑。
基本上,从不同的角度(视图)渲染3D模型并执行二维关键点检测。对于每个检测到的关键点,执行射线投射以确定与网格表面的交点。最后,将不同视图的所有交点组合起来,计算关键点在网格中的当前3D位置。可以定义视图相关的关键点索引,以仅提取在当前渲染中可见的点。Muke返回一个包含位置和最近顶点索引的3D关键点列表。
Muke处理过程
使用网格数据进行直接3D关键点识别将更准确,但仍然难以训练3D模型或找到它们的预训练权重。仅使用二维识别,可以使用整个关键点图像识别模型库。Muke内置了MediaPipe面部和姿态检测器,但可以扩展以使用任何其他二维关键点检测框架。
3D面部关键点估计(由VistaPrime创建的人头 CC署名)
该项目最初是为了实现一个简单快速的解决方案,用于3D关键点检测以进行重新拓扑。然而,它也可以用于任何需要3D关键点的其他应用,例如绑定、动画等。
安装
使用以下pip命令安装包
pip install muke
用法
Muke可以用作命令行工具,以特定格式(例如Wrap3)提取关键点。为此,需要创建一个配置文件,该文件定义了检测参数以及渲染视图。
配置
示例配置
{
"description": "MP Face",
"detector": "media-pipe-face",
"resolution": 1024,
"generator": "wrap3",
"views": [
{
"name": "frontal",
"rotation": 0,
"keypoints": [
4,
76,
306
]
}
]
}
要选择一系列关键点索引,可以定义一个start
(开始)和end
(结束)(包含)索引。还可以在该范围内跳过某些索引。以下是一个创建范围的示例(skip
是可选的)
{
"start": 10,
"end": 15,
"skip": [13, 14]
}
无限射线
对于每个视图,可以将infinite-ray
值设置为True
,以便通过网格向无限远处射出射线。网格上的每个交点都用作计算网格内关键点平均中心的位置。
演示
使用以下命令快速尝试Muke。
python -m muke assets/person.ply --display --resolution 1024
python -m muke assets/human_head.obj --display --resolution 1024 --detector media-pipe-face
python -m muke assets/human_head.obj --config config/media-pipe-face.json --display
帮助
usage: muke [-h] [--detector {media-pipe-pose,media-pipe-face}]
[--resolution RESOLUTION] [--infinite-ray] [--generator {wrap3}]
[--config CONFIG] [--load-raw] [--display] [--debug]
input
Detects keypoint locations in a 3d model.
positional arguments:
input Input mesh to process.
optional arguments:
-h, --help show this help message and exit
--detector {media-pipe-pose,media-pipe-face}
Detection method for 2d keypoint detection (default:
media-pipe-pose).
--resolution RESOLUTION
Render resolution for each view pass (default: 512).
--infinite-ray Send ray through mesh to infinity and use average of
intersections (default: False)
--generator {wrap3} Generator methods for output generation (default:
wrap3).
--config CONFIG Path to the configuration JSON file.
--load-raw Load mesh raw without post-processing (default: False)
--display Shows result rendering with keypoints (default: False)
--debug Shows debug frames and information (default: False)
库
还可以将Muke用作库,在现有的3D网格上检测关键点。
import open3d as o3d
from muke.Muke import Muke
from muke.detector.MediaPipePoseDetector import MediaPipePoseDetector
from muke.model.DetectionView import DetectionView
# load mesh from filesystem
mesh = o3d.io.read_triangle_mesh("assets/person.ply")
# define rendered views
keypoint_indexes = {28, 27, 26, 25, 24, 23, 12, 11, 14, 13, 16, 15, 5, 2, 0}
views = [
DetectionView("front", 0, keypoint_indexes),
DetectionView("back", 180, keypoint_indexes),
]
# detect keypoints
with Muke(MediaPipePoseDetector()) as m:
result = m.detect(mesh, views)
# present results
for kp in result:
print(f"KP {kp.index}: {kp.x:.2f} {kp.y:.2f} {kp.z:.2f}")
检测器
可以实现自定义关键点检测器。自定义检测器必须实现如以下示例所示的BaseDetector
接口。
import numpy as np
from muke.detector.BaseDetector import BaseDetector
from muke.detector.KeyPoint2 import KeyPoint2
class CustomDetector(BaseDetector):
def setup(self):
# todo: initialize the custom detector
pass
def detect(self, image: np.ndarray) -> [KeyPoint2]:
# todo: implement the custom 2d keypoint detection
pass
def release(self):
# todo: clean up allocated resources
pass
渲染器
当前版本使用pygfx作为轻量级和离屏渲染器,使用trimesh将模型加载到pygfx中,并使用Open3D进行射线投射。最初,使用trimesh进行所有操作,这已在trimesh-renderer分支中归档。Open3D也曾一度用于所有操作,但已在版本0.2.x
中归档,并在open3d-renderer分支中。
关于
MIT许可证 - 版权所有 (c) 2024 Florian Bruggisser
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分发
构建分发
muke-0.3.5.4-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 787240f71e8f4747ac5661cd5a258e027d2ccd7cb579ed931439d8360b2fbf4c |
|
MD5 | 6dd9ff28cee72f8214a394257da6a749 |
|
BLAKE2b-256 | d84132079feb531244fb60cb4d703289e315aba2d51356e159e4e5c34ba4c282 |