python - Mediapipe,将地标分配给顶点?

标签 python image-processing computer-vision blender mediapipe

Here是 mediapipe 用于其面部网格模型的 fbx 格式的面部。它有 468 个顶点。 Here是指数的可视化。

Here是mediapipes人脸网格模型的描述。它输出地标位置。

我怎么知道哪个地标属于哪个顶点? 例如在 blender 中。当我导入 fbx 人脸时,如何获得与 mediapipe 人脸网格模型的地标相同的索引?

最佳答案

似乎带有 fbx 模型的搅拌器中的索引与 mediapipe 面网格解决方案提供的索引相同。这些索引与 mediapipe 中的相同 canonical face model uv visualization . This answer提供了通过其索引获取地标的示例。

需要启用 Developer Extras。在编辑模式下,该选项显示在 Viewport Overlays > Developer > Indices 下,如下所示以获取 blender 中的索引。获取索引的替代选项可以是 found here .

我在下面展示了一个示例,其中左眼界标索引出现在规范的面部网格 uv 可视化中。

指数可视化

enter image description here

enter image description here

代码

代码基于,https://google.github.io/mediapipe/solutions/face_mesh.html .

import cv2
import mediapipe as mp
mp_drawing = mp.solutions.drawing_utils
mp_drawing_styles = mp.solutions.drawing_styles
mp_face_mesh = mp.solutions.face_mesh

# For static images:

import glob
IMAGE_FILES = glob.glob('img.jpg')


drawing_spec = mp_drawing.DrawingSpec(thickness=1, circle_radius=1)
with mp_face_mesh.FaceMesh(
    static_image_mode=True,
    max_num_faces=1,
    refine_landmarks=True,
    min_detection_confidence=0.5) as face_mesh:
  for idx, file in enumerate(IMAGE_FILES):
    image = cv2.imread(file)
    # Convert the BGR image to RGB before processing.
    results = face_mesh.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))

    # Print and draw face mesh landmarks on the image.
    if not results.multi_face_landmarks:
      continue
    annotated_image = image.copy()

    landmarks_list = [
        33, 7, 163, 144, 145, 153, 154, 155,
        133, 173, 157, 158, 159, 160, 161, 246
    ]

    for face_landmarks in results.multi_face_landmarks:
      #print('face_landmarks:', face_landmarks)

      print(len(face_landmarks.landmark))
    #   print(face_landmarks.landmark[7])

      for idx in landmarks_list:
        loc_x = int(face_landmarks.landmark[idx].x * image.shape[1])
        loc_y = int(face_landmarks.landmark[idx].y * image.shape[0])
        print(loc_x, loc_y)
        cv2.circle(annotated_image,(loc_x, loc_y), 2, (255,255,255), 2)

    cv2_imshow(annotated_image)

输出

enter image description here

演示笔记本

https://github.com/quickgrid/AI-Resources/blob/master/code-lab/computer_vision/Mediapipe_Python_Holistic_and_Face_Mesh.ipynb

关于python - Mediapipe,将地标分配给顶点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69167499/

相关文章:

image-processing - RGB 的 Gamma 校正算法与灰度的 Gamma 校正算法相同吗?

c++ - 谁能提供 "Skeleton Pruning by Contour Partitioning with Discrete Curve Evolution"算法的简单步骤

matlab - 寻找有关计算机视觉类(class)项目的想法

python - numpy 中结构化数组的形状

python - python 中的扩展切片?

python - 如何使用 python 将 RAW LOAD 从 scapy 转换为 KERBEROS 表示法

python - Django模型针对这种反向ForeignKey的最佳解决方案

iOS 捕获高分辨率照片,同时使用低 AVCaptureSessionPreset 进行视频输出

machine-learning - 使用翻转图像作为机器学习数据集

c++ - 如何在 OpenCV 中使用 SimpleBlobDetector?