python dlib 面部特征点检测

运行环境macos m2芯片 Python 3.11.7,python3.9都能通过,windows系统应该也是一样的效果

import dlib
import cv2
import matplotlib.pyplot as plt

# Load the image
image_path = 'path_to_your_image.jpg'  # Replace with the path to your image
image = cv2.imread(image_path)

# Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Initialize the dlib face detector
detector = dlib.get_frontal_face_detector()

# Initialize the shape predictor
predictor_path = 'shape_predictor_68_face_landmarks.dat'  # Replace with the path to your .dat file
predictor = dlib.shape_predictor(predictor_path)

# Detect faces in the image
faces = detector(gray)

# Loop over each detected face
for face in faces:
    # Get the landmarks
    landmarks = predictor(gray, face)

    # Loop over each landmark point
    for n in range(0, 68):
        x = landmarks.part(n).x
        y = landmarks.part(n).y
        cv2.circle(image, (x, y), 2, (0, 255, 0), -1)

# Convert the image back to RGB for displaying with matplotlib
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Display the image with detected landmarks
plt.imshow(image_rgb)
plt.axis('off')
plt.show()

 dlib 的亮点之一是其高精度的人脸检测和面部特征点检测功能,包含了用于检测 68 个面部特征点的预训练模型。

shape_predictor_68_face_landmarks.dat下载地址

链接: https://pan.baidu.com/s/1MhwLavLU2uWJnNo13gTLjQ 提取码: 5555
--来自百度网盘超级会员v9的分享 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

养牛大人

感谢您的鼓励!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值