import mediapipe as mp
import cv2
# 初始化 FaceMesh 模型 csdn ai给的代码
mp_face_mesh = mp.solutions.face_mesh
face_mesh = mp_face_mesh.FaceMesh(static_image_mode=False, max_num_faces=1, min_detection_confidence=0.5)
# 读取图像
image = cv2.imread('images/out00001.jpg')
# 转换颜色空间为 RGB 并进行人脸关键点检测
results = face_mesh.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
# 绘制人脸关键点
if results.multi_face_landmarks:
for face_landmarks in results.multi_face_landmarks:
for i, landmark in enumerate(face_landmarks.landmark):#i 坐标点序号, landmark 包含坐标
x = int(landmark.x * image.shape[1])
y = int(landmark.y * image.shape[0])
cv2.circle(image, (x, y), 2, (0, 255, 0), -1)
image = cv2.putText(image, str(i), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.3,(218, 112, 214), 1, 1)# 序号
# 显示图像
cv2.imshow('Face Mesh', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
mediapipe 很简单的程序, 标注坐标点,和坐标的序号
最新推荐文章于 2024-02-22 09:31:38 发布