dlib人脸配准(人脸对齐)

dlib人脸配准有两种方式。

  1. 一种是使用 get_face_chip()方法,使用5个关键点模型来进行配准,这种方法Dlib已经提供了完整的接口(imutils里也有类似函数, face_utils.FaceAligner,代码放在最后面)
  2. 另一种是自己使用68点关键点模型,根据关键点信息求解变换矩阵,然后把变换矩阵应用到整个图像上。

(1)使用 get_face_chip()方法实验结果:
在这里插入图片描述

import cv2
import dlib
import matplotlib.pyplot as plt

# 获取图片
image = cv2.imread('33.jpg')

image_gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# 使用特征提取器get_frontal_face_detector
detector = dlib.get_frontal_face_detector()

dets = detector(image_gray, 1)

for det in dets:
    # 将框画在原图上
    # cv2.rectangle  参数1:图片, 参数2:左上角坐标, 参数2:左上角坐标, 参数3:右下角坐标, 参数4:颜色(R,G,B), 参数2:粗细
    my_img = cv2.rectangle(image, (det.left(), det.top()), (det.right(), det.bottom()), (0, 255, 0), 2)

cv2.imshow("image", image)
cv2.waitKey(0)


# 人脸检测器
predictor = dlib.shape_predictor(r'./shape_predictor_68_face_landmarks.dat')
#
for det in dets:
    shape = predictor(image, det)
    # 将关键点绘制到人脸上
    for i in range(68):
        cv2.putText(image, str(i), (shape.part(i).x, shape.part(i).y), cv2.FONT_HERSHEY_DUPLEX, 0.1, (0, 255,0 ), 1, cv2.LINE_AA)
        cv2.circle(image, (shape.part(i).x, shape.part
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

叶叶梓梓

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值