效果图:
在这里插入图片描述

补充:下载shape_predictor_68_face_landmarks.dat
补充:我用pip方法下载失败有几个库,所以后来用的海龟编辑器里面的。

# -*- coding: utf-8 -*-

import dlib #dlib
import numpy
from skimage import io  # scikit-image
import cv2  # opencv-python

predictor_path = "D:\BaiduNetdiskDownload\shape_predictor_68_face_landmarks\shape_predictor_68_face_landmarks.dat"
#faces_path = "cl.jpg"  # 
faces_path = "./xinqing/8.jpg"  

'''加载人脸检测器、加载官方提供的模型构建特征提取器'''
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)

win = dlib.image_window()
img = io.imread(faces_path)

win.clear_overlay()
win.set_image(img)

dets = detector(img, 1)
print("Number of faces detected: {}".format(len(dets)))

for k, d in enumerate(dets):
    shape = predictor(img, d)
    landmark = numpy.matrix([[p.x, p.y] for p in shape.parts()])
    print("face_landmark:")
    print (landmark)  # 打印关键点矩阵
    win.add_overlay(shape)  #绘制特征点
    for idx, point in enumerate(landmark):
        pos = (point[0, 0], point[0, 1])
        cv2.putText(img, str(idx), pos, fontFace=cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,
                    fontScale=0.3, color=(0, 255, 0))
        # cv2.circle(img, pos, 3, color=(0, 255, 0))
    win.set_image(img)

dlib.hit_enter_to_continue()

Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐