Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Face Landmarker fails to correctly place landmarks #5792

Open
meminz opened this issue Dec 22, 2024 · 0 comments
Open

Face Landmarker fails to correctly place landmarks #5792

meminz opened this issue Dec 22, 2024 · 0 comments
Assignees
Labels
os:linux-non-arm Issues on linux distributions which run on x86-64 architecture. DOES NOT include ARM devices. platform:python MediaPipe Python issues task:face landmarker Issues related to Face Landmarker: Identify facial features for visual effects and avatars. type:support General questions

Comments

@meminz
Copy link

meminz commented Dec 22, 2024

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

None

OS Platform and Distribution

Linux Fedora 41

MediaPipe Tasks SDK version

No response

Task name (e.g. Image classification, Gesture recognition etc.)

Face Landmarker

Programming Language and version (e.g. C++, Python, Java)

Python 3.11

Describe the actual behavior

Face landmarks are placed outside of the actual face in the image

Describe the expected behaviour

Every landmark placed correctly inside the face in the image

Standalone code/steps you may have used to try to get what you need

import open3d as o3d import numpy as np import os, sys import matplotlib.pyplot as plt import mediapipe as mp from mediapipe.tasks.python import vision from mediapipe import solutions from mediapipe.framework.formats import landmark_pb2 def detectorInit(): BaseOptions = mp.tasks.BaseOptions FaceLandmarkerOptions = vision.FaceLandmarkerOptions options = FaceLandmarkerOptions( base_options=BaseOptions( model_asset_path="../face_landmarker.task"), output_face_blendshapes = False, output_facial_transformation_matrixes = False ) return vision.FaceLandmarker.create_from_options(options) def draw_landmarks_on_image(rgb_image, detection_result): face_landmarks_list = detection_result.face_landmarks annotated_image = np.copy(rgb_image) # Loop through the detected faces to visualize. for idx in range(len(face_landmarks_list)): face_landmarks = face_landmarks_list[idx] # Draw the face landmarks. face_landmarks_proto = landmark_pb2.NormalizedLandmarkList() face_landmarks_proto.landmark.extend([ landmark_pb2.NormalizedLandmark(x=landmark.x, y=landmark.y, z=landmark.z) for landmark in face_landmarks ]) # FACE MESH solutions.drawing_utils.draw_landmarks( image=annotated_image, landmark_list=face_landmarks_proto, connections=solutions.face_mesh.FACEMESH_TESSELATION, landmark_drawing_spec=None, connection_drawing_spec=solutions.drawing_styles.get_default_face_mesh_tesselation_style() ) # CONTOURS solutions.drawing_utils.draw_landmarks( image=annotated_image, landmark_list=face_landmarks_proto, connections=solutions.face_mesh.FACEMESH_CONTOURS, landmark_drawing_spec=None, connection_drawing_spec=solutions.drawing_styles.get_default_face_mesh_contours_style() ) # EYES solutions.drawing_utils.draw_landmarks( image=annotated_image, landmark_list=face_landmarks_proto, connections=solutions.face_mesh.FACEMESH_IRISES, landmark_drawing_spec=None, connection_drawing_spec=solutions.drawing_styles.get_default_face_mesh_iris_connections_style() ) return annotated_image def main(filename): try: in_mesh = o3d.io.read_triangle_mesh(filename, True) except: print("Error importing mesh.\n"); return in_mesh.translate(- in_mesh.get_axis_aligned_bounding_box().get_center()) diag = np.linalg.norm( in_mesh.get_max_bound() - in_mesh.get_min_bound() ) in_mesh.scale(1/diag, in_mesh.get_axis_aligned_bounding_box().get_center()) mesh = o3d.t.geometry.TriangleMesh(device=o3d.core.Device("CPU:0")).from_legacy(in_mesh) detector = detectorInit() size = 720 vis = o3d.visualization.Visualizer() vis.create_window(visible=False, width=size, height=size) vis.get_render_option().background_color = [0,0,0] vis.add_geometry(in_mesh) R = np.asarray( o3d.geometry.get_rotation_matrix_from_axis_angle([0, -np.pi/4, 0]) ) in_mesh.rotate(R, center = in_mesh.get_axis_aligned_bounding_box().get_center()) vis.update_geometry(in_mesh) img = ( np.asarray(vis.capture_screen_float_buffer(True)) * 255 ).astype(np.uint8) # plt.imsave(f"./snapshots/rotation_{i}.png", img) mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=img) detection_result = detector.detect(mp_image) if not detection_result.face_landmarks: print("Detection failed.") annotated_img = draw_landmarks_on_image(img, detection_result) plt.imsave(f"./snapshots/img_{i}.png", annotated_img) if name == "main": main(sys.argv[1])

Other info / Complete Logs

If I use PyVista instead of Open3D everything works just fine.
@kuaashish kuaashish added os:linux-non-arm Issues on linux distributions which run on x86-64 architecture. DOES NOT include ARM devices. task:face landmarker Issues related to Face Landmarker: Identify facial features for visual effects and avatars. platform:python MediaPipe Python issues type:support General questions labels Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os:linux-non-arm Issues on linux distributions which run on x86-64 architecture. DOES NOT include ARM devices. platform:python MediaPipe Python issues task:face landmarker Issues related to Face Landmarker: Identify facial features for visual effects and avatars. type:support General questions
Projects
None yet
Development

No branches or pull requests

2 participants