Ah, je comprends ! Voici un code qui va créer une déformation exagérée de la mâchoire, façon "meme" ou caricature :
import cv2
import mediapipe as mp
import numpy as np
def extreme_jaw_deform(image, landmarks, scale_factor=2.0, jaw_drop=1.5):
height, width = image.shape[:2]
map_x, map_y = np.meshgrid(np.arange(width), np.arange(height))
# Points de la mâchoire
jaw_points = [152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 129, 128, 127]
# Point central du menton
chin_x = int(landmarks.landmark[152].x * width)
chin_y = int(landmarks.landmark[152].y * height)
# Création d'une déformation extreme
for point_idx in jaw_points:
x = int(landmarks.landmark[point_idx].x * width)
y = int(landmarks.landmark[point_idx].y * height)
# Étirement horizontal extrême
dx = (x - width/2)
map_x += np.where(map_y > y - 50, dx * scale_factor * np.exp(-(map_y - y)**2/10000), 0)
# Étirement vertical de la mâchoire
dy = (y - chin_y)
map_y += np.where(map_y > y - 50, dy * jaw_drop * np.exp(-(map_x - x)**2/10000), 0)
map_x = map_x.astype(np.float32)
map_y = map_y.astype(np.float32)
# Application de la déformation
deformed = cv2.remap(image, map_x, map_y, cv2.INTER_LINEAR)
return deformed
# Initialisation de Mediapipe
mp_face_mesh = mp.solutions.face_mesh
face_mesh = mp_face_mesh.FaceMesh(static_image_mode=True)
# Lecture de l'image
image = cv2.imread('chemin_vers_votre_image.jpg')
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Détection du visage
results = face_mesh.process(image_rgb)
if results.multi_face_landmarks:
for face_landmarks in results.multi_face_landmarks:
# Application de la déformation extrême
deformed_image = extreme_jaw_deform(
image,
face_landmarks,
scale_factor=3.0, # Plus cette valeur est grande, plus la mâchoire sera large
jaw_drop=2.0 # Plus cette valeur est grande, plus la mâchoire sera allongée
)
# Affichage
cv2.imshow('Original', image)
cv2.imshow('Gigachad Mode', deformed_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
face_mesh.close()
Ce code va :
- Identifier tous les points de la mâchoire
- Créer une déformation qui étire horizontalement ET verticalement la mâchoire
- Appliquer une déformation non-linéaire pour un effet plus extrême
Vous pouvez jouer avec :
scale_factor : pour rendre la mâchoire plus ou moins large
jaw_drop : pour allonger plus ou moins la mâchoire
- Les valeurs dans les exponentielles (10000 dans le code) pour modifier la "brutalité" de la transition
Si vous voulez un effet encore plus extrême, vous pouvez :